aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--doc/ScintillaDoc.html23
-rw-r--r--include/Scintilla.h3
-rw-r--r--include/Scintilla.iface9
-rw-r--r--src/Editor.cxx30
-rw-r--r--src/Editor.h2
5 files changed, 49 insertions, 18 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index cd4939a55..41c3a5d43 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -2526,7 +2526,7 @@ struct Sci_TextToFind {
<a class="message" href="#SCI_SETCONTROLCHARSYMBOL">SCI_SETCONTROLCHARSYMBOL(int
symbol)</a><br />
<a class="message" href="#SCI_GETCONTROLCHARSYMBOL">SCI_GETCONTROLCHARSYMBOL</a><br />
- <a class="message" href="#SCI_SETCARETSTICKY">SCI_SETCARETSTICKY(bool useCaretStickyBehaviour)</a><br />
+ <a class="message" href="#SCI_SETCARETSTICKY">SCI_SETCARETSTICKY(int useCaretStickyBehaviour)</a><br />
<a class="message" href="#SCI_GETCARETSTICKY">SCI_GETCARETSTICKY</a><br />
<a class="message" href="#SCI_TOGGLECARETSTICKY">SCI_TOGGLECARETSTICKY</a><br />
</code>
@@ -2631,12 +2631,25 @@ struct Sci_TextToFind {
You can read back the current symbol with the <code>SCI_GETCONTROLCHARSYMBOL</code> message.
The default symbol value is 0.</p>
- <p><b id="SCI_SETCARETSTICKY">SCI_SETCARETSTICKY(bool useCaretStickyBehaviour)</b><br />
+ <p><b id="SCI_SETCARETSTICKY">SCI_SETCARETSTICKY(int useCaretStickyBehaviour)</b><br />
<b id="SCI_GETCARETSTICKY">SCI_GETCARETSTICKY</b><br />
<b id="SCI_TOGGLECARETSTICKY">SCI_TOGGLECARETSTICKY</b><br />
- These messages set, get or toggle the caretSticky flag which controls when the last position
- of the caret on the line is saved. When set to true, the position is not saved when you type
- a character, a tab, paste the clipboard content or press backspace.</p>
+ These messages set, get or toggle the caretSticky setting which controls when the last position
+ of the caret on the line is saved.</p>
+
+ <p>When set to <code>SC_CARETSTICKY_OFF</code> (0), the sticky flag is off; all text changes
+ (and all caret position changes) will remember the
+ caret's new horizontal position when moving to different lines. This is the default.</p>
+
+ <p>When set to <code>SC_CARETSTICKY_ON</code> (1), the sticky flag is on, and the only thing which will cause the editor to remember the
+ horizontal caret position is moving the caret with mouse or keyboard (left/right arrow keys, home/end keys, etc). </p>
+
+ <p>When set to <code>SC_CARETSTICKY_WHITESPACE</code> (2), the caret acts like mode 0 (sticky off) except under one
+ special case; when space or tab characters are inserted. (Including pasting <b>only space/tabs</b> -- undo, redo,
+ etc. do not exhibit this behavior..).</p>
+
+ <p><code>SCI_TOGGLECARETSTICKY</code> switches from <code>SC_CARETSTICKY_ON</code> and <code>SC_CARETSTICKY_WHITESPACE</code>
+ to <code>SC_CARETSTICKY_OFF</code> and from <code>SC_CARETSTICKY_OFF</code> to <code>SC_CARETSTICKY_ON</code>.</p>
<h2 id="Margins">Margins</h2>
diff --git a/include/Scintilla.h b/include/Scintilla.h
index b91c78c2a..efb536742 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -669,6 +669,9 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_FINDCOLUMN 2456
#define SCI_GETCARETSTICKY 2457
#define SCI_SETCARETSTICKY 2458
+#define SC_CARETSTICKY_OFF 0
+#define SC_CARETSTICKY_ON 1
+#define SC_CARETSTICKY_WHITESPACE 2
#define SCI_TOGGLECARETSTICKY 2459
#define SCI_SETPASTECONVERTENDINGS 2467
#define SCI_GETPASTECONVERTENDINGS 2468
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index d7c850840..f40530fda 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -1780,10 +1780,15 @@ fun int EncodedFromUTF8=2449(string utf8, stringresult encoded)
fun int FindColumn=2456(int line, int column)
# Can the caret preferred x position only be changed by explicit movement commands?
-get bool GetCaretSticky=2457(,)
+get int GetCaretSticky=2457(,)
# Stop the caret preferred x position changing when the user types.
-set void SetCaretSticky=2458(bool useCaretStickyBehaviour,)
+set void SetCaretSticky=2458(int useCaretStickyBehaviour,)
+
+enu CaretSticky=SC_CARETSTICKY_
+val SC_CARETSTICKY_OFF=0
+val SC_CARETSTICKY_ON=1
+val SC_CARETSTICKY_WHITESPACE=2
# Switch between sticky and non-sticky: meant to be bound to a key.
fun void ToggleCaretSticky=2459(,)
diff --git a/src/Editor.cxx b/src/Editor.cxx
index ecac75118..6119944c3 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -94,6 +94,15 @@ static inline bool IsControlCharacter(int ch) {
return ch >= 0 && ch < ' ';
}
+static inline bool IsAllSpacesOrTabs(char *s, unsigned int len) {
+ for (unsigned int i = 0; i < len; i++) {
+ // This is safe because IsSpaceOrTab() will return false for null terminators
+ if (!IsSpaceOrTab(s[i]))
+ return false;
+ }
+ return true;
+}
+
Editor::Editor() {
ctrlID = 0;
@@ -148,7 +157,7 @@ Editor::Editor() {
lineWidthMaxSeen = 0;
verticalScrollBarVisible = true;
endAtLastLine = true;
- caretSticky = false;
+ caretSticky = SC_CARETSTICKY_OFF;
multipleSelection = false;
additionalSelectionTyping = false;
multiPasteMode = SC_MULTIPASTE_ONCE;
@@ -3813,7 +3822,8 @@ void Editor::AddCharUTF(char *s, unsigned int len, bool treatAsDBCS) {
EnsureCaretVisible();
// Avoid blinking during rapid typing:
ShowCaretAtCurrentPosition();
- if (!caretSticky) {
+ if ((caretSticky == SC_CARETSTICKY_OFF) ||
+ ((caretSticky == SC_CARETSTICKY_WHITESPACE) && !IsAllSpacesOrTabs(s, len))) {
SetLastXChosen();
}
@@ -5072,21 +5082,21 @@ int Editor::KeyCommand(unsigned int iMessage) {
break;
case SCI_DELETEBACK:
DelCharBack(true);
- if (!caretSticky) {
+ if ((caretSticky == SC_CARETSTICKY_OFF) || (caretSticky == SC_CARETSTICKY_WHITESPACE)) {
SetLastXChosen();
}
EnsureCaretVisible();
break;
case SCI_DELETEBACKNOTLINE:
DelCharBack(false);
- if (!caretSticky) {
+ if ((caretSticky == SC_CARETSTICKY_OFF) || (caretSticky == SC_CARETSTICKY_WHITESPACE)) {
SetLastXChosen();
}
EnsureCaretVisible();
break;
case SCI_TAB:
Indent(true);
- if (!caretSticky) {
+ if (caretSticky == SC_CARETSTICKY_OFF) {
SetLastXChosen();
}
EnsureCaretVisible();
@@ -5094,7 +5104,7 @@ int Editor::KeyCommand(unsigned int iMessage) {
break;
case SCI_BACKTAB:
Indent(false);
- if (!caretSticky) {
+ if ((caretSticky == SC_CARETSTICKY_OFF) || (caretSticky == SC_CARETSTICKY_WHITESPACE)) {
SetLastXChosen();
}
EnsureCaretVisible();
@@ -6720,7 +6730,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_PASTE:
Paste();
- if (!caretSticky) {
+ if ((caretSticky == SC_CARETSTICKY_OFF) || (caretSticky == SC_CARETSTICKY_WHITESPACE)) {
SetLastXChosen();
}
EnsureCaretVisible();
@@ -7475,9 +7485,9 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
return endAtLastLine;
case SCI_SETCARETSTICKY:
- PLATFORM_ASSERT((wParam == 0) || (wParam == 1));
- if (caretSticky != (wParam != 0)) {
- caretSticky = wParam != 0;
+ PLATFORM_ASSERT((wParam >= SC_CARETSTICKY_OFF) && (wParam <= SC_CARETSTICKY_WHITESPACE));
+ if ((wParam >= SC_CARETSTICKY_OFF) && (wParam <= SC_CARETSTICKY_WHITESPACE)) {
+ caretSticky = wParam;
}
break;
diff --git a/src/Editor.h b/src/Editor.h
index 54411fad5..e7aa2e6ce 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -159,7 +159,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
int lineWidthMaxSeen;
bool verticalScrollBarVisible;
bool endAtLastLine;
- bool caretSticky;
+ int caretSticky;
bool multipleSelection;
bool additionalSelectionTyping;
int multiPasteMode;