From ff5918808d0a33dda52edf2b429d44b19b4a637d Mon Sep 17 00:00:00 2001
From: nyamatongwe
+
@@ -1226,6 +1227,11 @@ struct TextToFind {
characters up to the position on the line. In both cases, double byte characters count as a
single character. This is probably only useful with monospaced fonts.
SCI_FINDCOLUMN(int line, int column)
+ This message returns the position of a column on a line
+ taking the width of tabs into account. It treats a multi-byte character as a single column.
+ Column numbers, like lines start at 0.
SCI_POSITIONFROMPOINT(int x, int y)
SCI_POSITIONFROMPOINTCLOSE(int x, int y)
SCI_POSITIONFROMPOINT finds the closest character position to a point and
diff --git a/include/Scintilla.h b/include/Scintilla.h
index 78f3e093e..f20f0de22 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -586,6 +586,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_TARGETASUTF8 2447
#define SCI_SETLENGTHFORENCODE 2448
#define SCI_ENCODEDFROMUTF8 2449
+#define SCI_FINDCOLUMN 2456
#define SCI_STARTRECORD 3001
#define SCI_STOPRECORD 3002
#define SCI_SETLEXER 4001
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index 8fec74f66..d53f9c4e4 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -1595,6 +1595,10 @@ fun void SetLengthForEncode=2448(int bytes,)
# On error return 0.
fun int EncodedFromUTF8=2449(string utf8, stringresult encoded)
+# Find the position of a column on a line taking into account tabs and
+# multi-byte characters. If beyond end of line, return line end position.
+fun int FindColumn=2456(int line, int column)
+
# Start notifying the container of all key presses and commands.
fun void StartRecord=3001(,)
diff --git a/src/Document.cxx b/src/Document.cxx
index 97abd6254..c06397fa8 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -653,7 +653,7 @@ int Document::FindColumn(int line, int column) {
int position = LineStart(line);
int columnCurrent = 0;
if ((line >= 0) && (line < LinesTotal())) {
- while (columnCurrent < column) {
+ while ((columnCurrent < column) && (position < Length())) {
char ch = cb.CharAt(position);
if (ch == '\t') {
columnCurrent = NextTab(columnCurrent, tabInChars);
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 81cf3bd47..3b16c9783 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -6307,6 +6307,9 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_GETCOLUMN:
return pdoc->GetColumn(wParam);
+ case SCI_FINDCOLUMN:
+ return pdoc->FindColumn(wParam, lParam);
+
case SCI_SETHSCROLLBAR :
if (horizontalScrollBarVisible != (wParam != 0)) {
horizontalScrollBarVisible = wParam != 0;
--
cgit v1.2.3