From 3def602e8b7b6f45003cb95f7a74979118ae0e4a Mon Sep 17 00:00:00 2001

From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= jaakko.keranen@iki.fi

Date: Sun, 13 Dec 2020 13:08:05 +0200

Subject: [PATCH 1/1] macOS: Disable page navigation while editing text

The Cmd+Left/Right keys used both for page navigation (by default) and for moving the cursor inside text editor. The input widget keys should take precedence.


src/macos.h | 2 ++

src/macos.m | 77 +++++++++++++++++++++++++++++++++++---------

src/ui/inputwidget.c | 18 +++++++++++

3 files changed, 82 insertions(+), 15 deletions(-)

diff --git a/src/macos.h b/src/macos.h

index f948a0db..a59351e6 100644

--- a/src/macos.h

+++ b/src/macos.h

@@ -33,4 +33,6 @@ void registerURLHandler_MacOS (void);

void setupApplication_MacOS (void);

void insertMenuItems_MacOS (const char *menuLabel, int atIndex, const iMenuItem *items, size_t count);

void enableMenu_MacOS (const char *menuLabel, iBool enable);

+void enableMenuItem_MacOS (const char *menuItemCommand, iBool enable);

+void enableMenuItemsByKey_MacOS (int key, int kmods, iBool enable);

void handleCommand_MacOS (const char *cmd);

diff --git a/src/macos.m b/src/macos.m

index c8793eac..4e214923 100644

--- a/src/macos.m

+++ b/src/macos.m

@@ -367,40 +367,86 @@ void enableMenu_MacOS(const char *menuLabel, iBool enable) {

 [label release];

}

-static void setShortcut_NSMenuItem_(NSMenuItem *item, int key, int kmods) {

+void enableMenuItem_MacOS(const char *menuItemCommand, iBool enable) {

+}

+static iString *composeKeyEquivalent_(int key, int kmods, NSEventModifierFlags *modMask) {

 if (key == SDLK_LEFT) {

 }

 else if (key == SDLK_RIGHT) {

 }

 else if (key == SDLK_UP) {

 }

 else if (key == SDLK_DOWN) {

 }

 else if (key) {

 }

 if (kmods & KMOD_GUI) {

 }

 if (kmods & KMOD_ALT) {

 }

 if (kmods & KMOD_CTRL) {

 }

 if (kmods & KMOD_SHIFT) {

 }

+}

+void enableMenuItemsByKey_MacOS(int key, int kmods, iBool enable) {

+}

+static void setShortcut_NSMenuItem_(NSMenuItem *item, int key, int kmods) {

 [item setKeyEquivalentModifierMask:modMask];

}

void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *items, size_t count) {

@@ -412,6 +458,7 @@ void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *

                                       keyEquivalent:@""

                                             atIndex:atIndex];

 NSMenu *menu = [[NSMenu alloc] initWithTitle:[NSString stringWithUTF8String:menuLabel]];

 for (size_t i = 0; i < count; ++i) {

     const char *label = items[i].label;

     if (label[0] == '\r') {

diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c

index 59608151..c4c7475e 100644

--- a/src/ui/inputwidget.c

+++ b/src/ui/inputwidget.c

@@ -30,9 +30,22 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

#include <SDL_clipboard.h>

#include <SDL_timer.h>

+#if defined (iPlatformApple)

+# include "macos.h"

+#endif

static const int refreshInterval_InputWidget_ = 256;

static const size_t maxUndo_InputWidget_ = 64;

+static void enableEditorKeysInMenus_(iBool enable) {

+#if defined (iPlatformApple)

+#else

+#endif

+}

iDeclareType(InputUndo)

struct Impl_InputUndo {

@@ -114,6 +127,9 @@ void init_InputWidget(iInputWidget *d, size_t maxLen) {

}

void deinit_InputWidget(iInputWidget *d) {

 delete_TextBuf(d->buffered);

 clearUndo_InputWidget_(d);

 deinit_Array(&d->undoStack);

@@ -279,6 +295,7 @@ void begin_InputWidget(iInputWidget *d) {

 else {

     iZap(d->mark);

 }

}

void end_InputWidget(iInputWidget *d, iBool accept) {

@@ -287,6 +304,7 @@ void end_InputWidget(iInputWidget *d, iBool accept) {

     /* Was not active. */

     return;

 }

 if (!accept) {

     setCopy_Array(&d->text, &d->oldText);

 }

--

2.25.1

Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/work%2Fv1.10/patch/3def602e8b7b6f45003cb95f7a74979118ae0e4a.patch
Status Code
Success (20)
Meta
text/plain
Capsule Response Time
153.807274 milliseconds
Gemini-to-HTML Time
1.76583 milliseconds

This content has been proxied by September (ba2dc).