[patch] GtkEntry-like move to word boundaries

View: New views
6 Messages — Rating Filter:   Alert me  

[patch] GtkEntry-like move to word boundaries

by Nick Treleaven-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
I made a patch for GTK Scintilla to move to the end of a word e.g. when
pressing Ctrl-right (instead of the start). This is more like what GTK
widgets do by default, such as GtkEntry.

We've been testing it in the Geany IDE SVN for some weeks, combined  
with using SCI_SETWHITESPACECHARS to ignore punctuation.

Is it suitable to be applied by default?

Thanks,
Nick

[gtk-word-boundaries.patch]

Index: ScintillaGTK.cxx
===================================================================
--- ScintillaGTK.cxx (revision 1671)
+++ ScintillaGTK.cxx (revision 1672)
@@ -285,6 +285,9 @@
 
  static sptr_t DirectFunction(ScintillaGTK *sciThis,
                              unsigned int iMessage, uptr_t wParam, sptr_t lParam);
+
+protected:
+ virtual int KeyCommand(unsigned int iMessage);
 };
 
 enum {
@@ -2720,3 +2723,32 @@
 void scintilla_release_resources(void) {
  Platform_Finalise();
 }
+
+int ScintillaGTK::KeyCommand(unsigned int iMessage) {
+ switch (iMessage) {
+ /* Try to act more like a GtkWidget, e.g. GtkEntry.
+ * The container app should also call SCI_SETWHITESPACECHARS to include punctuation
+ * chars as whitespace. */
+ case SCI_WORDRIGHT:
+ MovePositionTo(MovePositionSoVisible(pdoc->NextWordEnd(currentPos, 1), 1));
+ SetLastXChosen();
+ break;
+ case SCI_WORDRIGHTEXTEND:
+ MovePositionTo(MovePositionSoVisible(pdoc->NextWordEnd(currentPos, 1), 1), selStream);
+ SetLastXChosen();
+ break;
+ case SCI_DELWORDRIGHT: {
+ int endWord = pdoc->NextWordEnd(currentPos, 1);
+ pdoc->DeleteChars(currentPos, endWord - currentPos);
+ }
+ break;
+ default:
+ return ScintillaBase::KeyCommand(iMessage);
+ }
+ /* Mimic what ScintillaBase::KeyCommand would do as we're overriding it. */
+ if (ac.Active())
+ ac.Cancel();
+ if (ct.inCallTipMode)
+ ct.CallTipCancel();
+ return 0;
+}



_______________________________________________
Scintilla-interest mailing list
Scintilla-interest@...
http://mailman.lyra.org/mailman/listinfo/scintilla-interest

Re: [patch] GtkEntry-like move to word boundaries

by Neil Hodgson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nick Treleaven:

> I made a patch for GTK Scintilla to move to the end of a word e.g. when
> pressing Ctrl-right (instead of the start).

   SCI_WORDRIGHTEND and SCI_WORDRIGHTENDEXTEND are already defined in
Scintilla. The normal mechanism in Scintilla is to define variant
commands rather than a command that adapts to the platform. This
allows applications to decide whether to map keys to platform-specific
behaviour or to choose the same effect on all platforms.

   Neil
_______________________________________________
Scintilla-interest mailing list
Scintilla-interest@...
http://mailman.lyra.org/mailman/listinfo/scintilla-interest

Re: [patch] GtkEntry-like move to word boundaries

by Nick Treleaven-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 07/31/2007 05:45:32 AM, Neil Hodgson wrote:

> Nick Treleaven:
>
> > I made a patch for GTK Scintilla to move to the end of a word e.g.
> when
> > pressing Ctrl-right (instead of the start).
>
>    SCI_WORDRIGHTEND and SCI_WORDRIGHTENDEXTEND are already defined in
> Scintilla. The normal mechanism in Scintilla is to define variant
> commands rather than a command that adapts to the platform. This
> allows applications to decide whether to map keys to platform-
> specific
> behaviour or to choose the same effect on all platforms.
>
OK, great - I just got around to doing this instead. Should I make a
patch to add SCI_DELWORDRIGHTEND for Editor.cxx? (If so, should there
be a SCI_DELWORDLEFTEND for symmetry?). Then it's easy to setup
Scintilla for Gtk-like word boundary handling.

Thanks,
Nick

_______________________________________________
Scintilla-interest mailing list
Scintilla-interest@...
http://mailman.lyra.org/mailman/listinfo/scintilla-interest

Re: [patch] GtkEntry-like move to word boundaries

by Neil Hodgson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nick Treleaven:

> OK, great - I just got around to doing this instead. Should I make a
> patch to add SCI_DELWORDRIGHTEND for Editor.cxx?

   Yes.

> (If so, should there
> be a SCI_DELWORDLEFTEND for symmetry?).

   Only if there is a real difference in behaviour. The Windows and
GTK+ behaviours look equivalent for Ctrl+Backspace.

   Neil
_______________________________________________
Scintilla-interest mailing list
Scintilla-interest@...
http://mailman.lyra.org/mailman/listinfo/scintilla-interest

Re: [patch] GtkEntry-like move to word boundaries

by Nick Treleaven-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 08/16/2007 02:29:44 PM, Neil Hodgson wrote:
> Nick Treleaven:
>
> > OK, great - I just got around to doing this instead. Should I make
> a
> > patch to add SCI_DELWORDRIGHTEND for Editor.cxx?
>
>    Yes.
>
OK, attached. (I didn't update the docs though).

> > (If so, should there
> > be a SCI_DELWORDLEFTEND for symmetry?).
>
>    Only if there is a real difference in behaviour. The Windows and
> GTK+ behaviours look equivalent for Ctrl+Backspace.
>
Yes, it's not necessary.

Thanks,
Nick


[sci-del-word-right-end.patch]

Index: include/Scintilla.h
===================================================================
RCS file: /cvsroot/scintilla/scintilla/include/Scintilla.h,v
retrieving revision 1.193
diff -u -r1.193 Scintilla.h
--- include/Scintilla.h 26 Jul 2007 07:28:36 -0000 1.193
+++ include/Scintilla.h 16 Aug 2007 16:14:43 -0000
@@ -505,6 +505,7 @@
 #define SCI_ZOOMOUT 2334
 #define SCI_DELWORDLEFT 2335
 #define SCI_DELWORDRIGHT 2336
+#define SCI_DELWORDRIGHTEND 2518
 #define SCI_LINECUT 2337
 #define SCI_LINEDELETE 2338
 #define SCI_LINETRANSPOSE 2339
Index: include/Scintilla.iface
===================================================================
RCS file: /cvsroot/scintilla/scintilla/include/Scintilla.iface,v
retrieving revision 1.319
diff -u -r1.319 Scintilla.iface
--- include/Scintilla.iface 31 Jul 2007 04:06:57 -0000 1.319
+++ include/Scintilla.iface 16 Aug 2007 16:14:45 -0000
@@ -1318,6 +1318,9 @@
 # Delete the word to the right of the caret.
 fun void DelWordRight=2336(,)
 
+# Delete the word to the right of the caret, but not the trailing non-word characters.
+fun void DelWordRightEnd=2518(,)
+
 # Cut the line containing the caret.
 fun void LineCut=2337(,)
 
Index: src/Editor.cxx
===================================================================
RCS file: /cvsroot/scintilla/scintilla/src/Editor.cxx,v
retrieving revision 1.400
diff -u -r1.400 Editor.cxx
--- src/Editor.cxx 28 Jul 2007 01:04:59 -0000 1.400
+++ src/Editor.cxx 16 Aug 2007 16:14:49 -0000
@@ -3933,6 +3933,7 @@
  case SCI_VCHOMEWRAPEXTEND:
  case SCI_DELWORDLEFT:
  case SCI_DELWORDRIGHT:
+ case SCI_DELWORDRIGHTEND:
  case SCI_DELLINELEFT:
  case SCI_DELLINERIGHT:
  case SCI_LINECOPY:
@@ -4494,6 +4495,11 @@
  pdoc->DeleteChars(currentPos, endWord - currentPos);
  }
  break;
+ case SCI_DELWORDRIGHTEND: {
+ int endWord = pdoc->NextWordEnd(currentPos, 1);
+ pdoc->DeleteChars(currentPos, endWord - currentPos);
+ }
+ break;
  case SCI_DELLINELEFT: {
  int line = pdoc->LineFromPosition(currentPos);
  int start = pdoc->LineStart(line);
@@ -7171,6 +7177,7 @@
  case SCI_ZOOMOUT:
  case SCI_DELWORDLEFT:
  case SCI_DELWORDRIGHT:
+ case SCI_DELWORDRIGHTEND:
  case SCI_DELLINELEFT:
  case SCI_DELLINERIGHT:
  case SCI_LINECOPY:



_______________________________________________
Scintilla-interest mailing list
Scintilla-interest@...
http://mailman.lyra.org/mailman/listinfo/scintilla-interest

Re: [patch] GtkEntry-like move to word boundaries

by Neil Hodgson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nick Treleaven:

> OK, attached. (I didn't update the docs though).

   Committed.

   Neil
_______________________________________________
Scintilla-interest mailing list
Scintilla-interest@...
http://mailman.lyra.org/mailman/listinfo/scintilla-interest