From 0d6fd0c6bc452f41919bbdf8dcc9b3d6fbc83205 Mon Sep 17 00:00:00 2001
From: Martijn Laan <1092369+martijnlaan@users.noreply.github.com>
Date: Wed, 31 Jul 2024 21:49:44 +1000
Subject: Feature [feature-requests:#1524]. Add SCI_LINEINDENT and
SCI_LINEDEDENT. These force the multiline behaviour of SCI_TAB and
SCI_BACKTAB.
---
call/ScintillaCall.cxx | 8 ++++++++
doc/ScintillaDoc.html | 6 ++++++
doc/ScintillaHistory.html | 4 ++++
include/Scintilla.h | 2 ++
include/Scintilla.iface | 9 ++++++++-
include/ScintillaCall.h | 2 ++
include/ScintillaMessages.h | 2 ++
src/Editor.cxx | 16 +++++++++++-----
src/Editor.h | 2 +-
9 files changed, 44 insertions(+), 7 deletions(-)
diff --git a/call/ScintillaCall.cxx b/call/ScintillaCall.cxx
index d1732a463..4508210db 100644
--- a/call/ScintillaCall.cxx
+++ b/call/ScintillaCall.cxx
@@ -1979,10 +1979,18 @@ void ScintillaCall::Tab() {
Call(Message::Tab);
}
+void ScintillaCall::LineIndent() {
+ Call(Message::LineIndent);
+}
+
void ScintillaCall::BackTab() {
Call(Message::BackTab);
}
+void ScintillaCall::LineDedent() {
+ Call(Message::LineDedent);
+}
+
void ScintillaCall::NewLine() {
Call(Message::NewLine);
}
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index b9a5971b2..b320621cf 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -6929,6 +6929,9 @@ struct Sci_TextToFindFull {
SCI_VERTICALCENTRECARET |
+ SCI_LINEINDENT |
+
+ SCI_LINEDEDENT |
@@ -6971,6 +6974,9 @@ struct Sci_TextToFindFull {
as appropriate for SCI_[[VC]HOME|LINEEND]*
.
+ The SCI_LINE[INDENT|DEDENT]
commands are like SCI_[BACK]TAB
but force the
+ multiline behaviour of the second.
+
The SCI_SCROLLTO[START|END]
commands scroll the document to the start
or end without changing the selection. These commands match macOS platform conventions for the behaviour of the
home
and end
keys. Scintilla can be made to match macOS applications
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index 3a820fb92..90e82cc41 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -599,6 +599,10 @@
Add SCI_GETUNDOSEQUENCE to determine whether an undo sequence is active and its nesting depth.
+
+ Add SCI_LINEINDENT and SCI_LINEDEDENT.
+ Feature #1524.
+
Release 5.5.1
diff --git a/include/Scintilla.h b/include/Scintilla.h
index d97da016f..6fec9be58 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -756,7 +756,9 @@ typedef sptr_t (*SciFnDirectStatus)(sptr_t ptr, unsigned int iMessage, uptr_t wP
#define SCI_CANCEL 2325
#define SCI_DELETEBACK 2326
#define SCI_TAB 2327
+#define SCI_LINEINDENT 2813
#define SCI_BACKTAB 2328
+#define SCI_LINEDEDENT 2814
#define SCI_NEWLINE 2329
#define SCI_FORMFEED 2330
#define SCI_VCHOME 2331
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index c04d23a80..25201cf47 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -1993,9 +1993,16 @@ fun void DeleteBack=2326(,)
# If more than one line selected, indent the lines.
fun void Tab=2327(,)
-# Dedent the selected lines.
+# Indent the current and selected lines.
+fun void LineIndent=2813(,)
+
+# If selection is empty or all on one line dedent the line if caret is at start, else move caret.
+# If more than one line selected, dedent the lines.
fun void BackTab=2328(,)
+# Dedent the current and selected lines.
+fun void LineDedent=2814(,)
+
# Insert a new line, may use a CRLF, CR or LF depending on EOL mode.
fun void NewLine=2329(,)
diff --git a/include/ScintillaCall.h b/include/ScintillaCall.h
index 02c383883..065a60ac5 100644
--- a/include/ScintillaCall.h
+++ b/include/ScintillaCall.h
@@ -540,7 +540,9 @@ public:
void Cancel();
void DeleteBack();
void Tab();
+ void LineIndent();
void BackTab();
+ void LineDedent();
void NewLine();
void FormFeed();
void VCHome();
diff --git a/include/ScintillaMessages.h b/include/ScintillaMessages.h
index c511720c5..847ec0881 100644
--- a/include/ScintillaMessages.h
+++ b/include/ScintillaMessages.h
@@ -459,7 +459,9 @@ enum class Message {
Cancel = 2325,
DeleteBack = 2326,
Tab = 2327,
+ LineIndent = 2813,
BackTab = 2328,
+ LineDedent = 2814,
NewLine = 2329,
FormFeed = 2330,
VCHome = 2331,
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 0561b42f8..588f22e4d 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -2934,7 +2934,9 @@ void Editor::NotifyMacroRecord(Message iMessage, uptr_t wParam, sptr_t lParam) {
case Message::Cancel:
case Message::DeleteBack:
case Message::Tab:
+ case Message::LineIndent:
case Message::BackTab:
+ case Message::LineDedent:
case Message::FormFeed:
case Message::VCHome:
case Message::VCHomeExtend:
@@ -3954,7 +3956,8 @@ int Editor::KeyCommand(Message iMessage) {
EnsureCaretVisible();
break;
case Message::Tab:
- Indent(true);
+ case Message::LineIndent:
+ Indent(true, iMessage == Message::LineIndent);
if (caretSticky == CaretSticky::Off) {
SetLastXChosen();
}
@@ -3962,7 +3965,8 @@ int Editor::KeyCommand(Message iMessage) {
ShowCaretAtCurrentPosition(); // Avoid blinking
break;
case Message::BackTab:
- Indent(false);
+ case Message::LineDedent:
+ Indent(false, iMessage == Message::LineDedent);
if ((caretSticky == CaretSticky::Off) || (caretSticky == CaretSticky::WhiteSpace)) {
SetLastXChosen();
}
@@ -4065,14 +4069,14 @@ int Editor::KeyDownWithModifiers(Keys key, KeyMod modifiers, bool *consumed) {
}
}
-void Editor::Indent(bool forwards) {
+void Editor::Indent(bool forwards, bool lineIndent) {
UndoGroup ug(pdoc);
for (size_t r=0; rSciLineFromPosition(sel.Range(r).anchor.Position());
Sci::Position caretPosition = sel.Range(r).caret.Position();
const Sci::Line lineCurrentPos = pdoc->SciLineFromPosition(caretPosition);
- if (lineOfAnchor == lineCurrentPos) {
+ if (lineOfAnchor == lineCurrentPos && !lineIndent) {
if (forwards) {
pdoc->DeleteChars(sel.Range(r).Start().Position(), sel.Range(r).Length());
caretPosition = sel.Range(r).caret.Position();
@@ -4115,7 +4119,7 @@ void Editor::Indent(bool forwards) {
sel.Range(r) = SelectionRange(newPos);
}
}
- } else { // Multiline
+ } else { // Multiline or LineIndent
const Sci::Position anchorPosOnLine = sel.Range(r).anchor.Position() -
pdoc->LineStart(lineOfAnchor);
const Sci::Position currentPosPosOnLine = caretPosition -
@@ -8175,7 +8179,9 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
case Message::Cancel:
case Message::DeleteBack:
case Message::Tab:
+ case Message::LineIndent:
case Message::BackTab:
+ case Message::LineDedent:
case Message::NewLine:
case Message::FormFeed:
case Message::VCHome:
diff --git a/src/Editor.h b/src/Editor.h
index 50aa9a660..e42f36573 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -505,7 +505,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
virtual int KeyDefault(Scintilla::Keys /* key */, Scintilla::KeyMod /*modifiers*/);
int KeyDownWithModifiers(Scintilla::Keys key, Scintilla::KeyMod modifiers, bool *consumed);
- void Indent(bool forwards);
+ void Indent(bool forwards, bool lineTab);
virtual std::unique_ptr CaseFolderForEncoding();
Sci::Position FindText(Scintilla::uptr_t wParam, Scintilla::sptr_t lParam);
--
cgit v1.2.3