aboutsummaryrefslogtreecommitdiff
path: root/src/scintilla_backports/6160_a1a9cde51997.patch
blob: 093ba79aebc3306a04bbff0b1937514f573e863f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# HG changeset patch
# User Vicente
# Date 1491085058 -36000
# Node ID a1a9cde519976fa12e46224d6cd57483bc4633ae
# Parent  67865d8e5a374e2cf9468e9b2638901342b1dca0
Added "Reverse Selected Lines" as SCI_LINEREVERSE.

diff -r 67865d8e5a37 -r a1a9cde51997 doc/ScintillaDoc.html
--- a/doc/ScintillaDoc.html	Sat Apr 01 13:30:58 2017 +1100
+++ b/doc/ScintillaDoc.html	Sun Apr 02 08:17:38 2017 +1000
@@ -5199,15 +5199,18 @@
           <td><code>SCI_DELLINERIGHT</code></td>
 
           <td><code>SCI_LINEDELETE</code></td>
-        </tr>
-
-        <tr>
+
           <td><code>SCI_LINECUT</code></td>
+        </tr>
+
+        <tr>
 
           <td><code>SCI_LINECOPY</code></td>
 
           <td><code>SCI_LINETRANSPOSE</code></td>
 
+          <td><code>SCI_LINEREVERSE</code></td>
+
           <td><code>SCI_LINEDUPLICATE</code></td>
         </tr>
 
diff -r 67865d8e5a37 -r a1a9cde51997 doc/ScintillaHistory.html
--- a/doc/ScintillaHistory.html	Sat Apr 01 13:30:58 2017 +1100
+++ b/doc/ScintillaHistory.html	Sun Apr 02 08:17:38 2017 +1000
@@ -527,6 +527,9 @@
 	Released 21 March 2017.
 	</li>
 	<li>
+	Added "Reverse Selected Lines" feature.
+	</li>
+	<li>
 	Updated case conversion and character categories to Unicode 9.
 	</li>
 	<li>
diff -r 67865d8e5a37 -r a1a9cde51997 include/Scintilla.h
--- a/include/Scintilla.h	Sat Apr 01 13:30:58 2017 +1100
+++ b/include/Scintilla.h	Sun Apr 02 08:17:38 2017 +1000
@@ -638,6 +638,7 @@
 #define SCI_LINECUT 2337
 #define SCI_LINEDELETE 2338
 #define SCI_LINETRANSPOSE 2339
+#define SCI_LINEREVERSE 2354
 #define SCI_LINEDUPLICATE 2404
 #define SCI_LOWERCASE 2340
 #define SCI_UPPERCASE 2341
diff -r 67865d8e5a37 -r a1a9cde51997 include/Scintilla.iface
--- a/include/Scintilla.iface	Sat Apr 01 13:30:58 2017 +1100
+++ b/include/Scintilla.iface	Sun Apr 02 08:17:38 2017 +1000
@@ -1614,6 +1614,9 @@
 # Switch the current line with the previous.
 fun void LineTranspose=2339(,)
 
+# Reverse order of selected lines.
+fun void LineReverse=2354(,)
+
 # Duplicate the current line.
 fun void LineDuplicate=2404(,)
 
diff -r 67865d8e5a37 -r a1a9cde51997 src/Editor.cxx
--- a/src/Editor.cxx	Sat Apr 01 13:30:58 2017 +1100
+++ b/src/Editor.cxx	Sun Apr 02 08:17:38 2017 +1000
@@ -2800,6 +2800,7 @@
 	case SCI_LINECUT:
 	case SCI_LINEDELETE:
 	case SCI_LINETRANSPOSE:
+	case SCI_LINEREVERSE:
 	case SCI_LINEDUPLICATE:
 	case SCI_LOWERCASE:
 	case SCI_UPPERCASE:
@@ -2967,6 +2968,32 @@
 	}
 }
 
+void Editor::LineReverse() {
+	const Sci::Line lineStart = pdoc->LineFromPosition(sel.RangeMain().Start().Position());
+	const Sci::Line lineEnd = pdoc->LineFromPosition(sel.RangeMain().End().Position()-1);
+	const Sci::Line lineDiff = lineEnd - lineStart;
+	if (lineDiff <= 0)
+		return;
+	UndoGroup ug(pdoc);
+	for (Sci::Line i=(lineDiff+1)/2-1; i>=0; --i) {
+		const Sci::Line lineNum2 = lineEnd - i;
+		const Sci::Line lineNum1 = lineStart + i;
+		Sci::Position lineStart2 = pdoc->LineStart(lineNum2);
+		const Sci::Position lineStart1 = pdoc->LineStart(lineNum1);
+		const std::string line2 = RangeText(lineStart2, pdoc->LineEnd(lineNum2));
+		const std::string line1 = RangeText(lineStart1, pdoc->LineEnd(lineNum1));
+		const Sci::Position lineLen2 = static_cast<Sci::Position>(line2.length());
+		const Sci::Position lineLen1 = static_cast<Sci::Position>(line1.length());
+		pdoc->DeleteChars(lineStart2, lineLen2);
+		pdoc->DeleteChars(lineStart1, lineLen1);
+		lineStart2 -= lineLen1;
+		pdoc->InsertString(lineStart2, line1.c_str(), lineLen1);
+		pdoc->InsertString(lineStart1, line2.c_str(), lineLen2);
+	}
+	// Wholly select all affected lines
+	sel.RangeMain() = SelectionRange(pdoc->LineStart(lineStart), pdoc->LineStart(lineEnd+1));
+}
+
 void Editor::Duplicate(bool forLine) {
 	if (sel.Empty()) {
 		forLine = true;
@@ -3809,6 +3836,9 @@
 	case SCI_LINETRANSPOSE:
 		LineTranspose();
 		break;
+	case SCI_LINEREVERSE:
+		LineReverse();
+		break;
 	case SCI_LINEDUPLICATE:
 		Duplicate(true);
 		break;
@@ -7453,6 +7483,7 @@
 	case SCI_LINECUT:
 	case SCI_LINEDELETE:
 	case SCI_LINETRANSPOSE:
+	case SCI_LINEREVERSE:
 	case SCI_LINEDUPLICATE:
 	case SCI_LOWERCASE:
 	case SCI_UPPERCASE:
diff -r 67865d8e5a37 -r a1a9cde51997 src/Editor.h
--- a/src/Editor.h	Sat Apr 01 13:30:58 2017 +1100
+++ b/src/Editor.h	Sun Apr 02 08:17:38 2017 +1000
@@ -460,6 +460,7 @@
 	virtual std::string CaseMapString(const std::string &s, int caseMapping);
 	void ChangeCaseOfSelection(int caseMapping);
 	void LineTranspose();
+	void LineReverse();
 	void Duplicate(bool forLine);
 	virtual void CancelModes();
 	void NewLine();