From f49573bf08c3891ad828a925cef6f1806ecb7bff Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Wed, 16 Mar 2016 19:13:05 -0400 Subject: [PATCH] Fix linux bug and improve tabstop functionality --- src/clipboard.d | 4 ++-- src/view.d | 14 ++++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/clipboard.d b/src/clipboard.d index 9daf9ba6..3af3998b 100644 --- a/src/clipboard.d +++ b/src/clipboard.d @@ -20,8 +20,8 @@ class Clipboard { version(linux) { import std.exception: collectException; - string[] copyCmd; - string[] pasteCmd; + static string[] copyCmd; + static string[] pasteCmd; static bool init() { if (collectException(execute(["xsel", "-h"]))) { diff --git a/src/view.d b/src/view.d index b12c7363..4c1a752d 100644 --- a/src/view.d +++ b/src/view.d @@ -67,11 +67,12 @@ class View { } int getCharPosition(int lineNum, int visualPosition) { - int numTabs = numOccurences(buf.lines[lineNum].replaceAll(regex("\t"), "\t" ~ emptyString(tabSize-1))[0 .. visualPosition], '\t'); - foreach (i; 0 .. numTabs) { - visualPosition -= tabSize-1; + string visualLine = buf.lines[lineNum].replaceAll(regex("\t"), "\t" ~ emptyString(tabSize-1)); + if (visualPosition > visualLine.length) { + visualPosition = cast(int) visualLine.length; } - return visualPosition; + int numTabs = numOccurences(visualLine[0 .. visualPosition], '\t'); + return visualPosition - (tabSize-1) * numTabs; } void cursorUp() { @@ -135,17 +136,14 @@ class View { cursorLeft(); } else if (e.key == Key.mouseLeft) { cursor.y = e.y + topline; - cursor.x = getCharPosition(cursor.y, e.x) - xOffset; if (cursor.y - topline > height-1) { cursor.y = height + topline-1; } if (cursor.y > buf.lines.length) { cursor.y = cast(int) buf.lines.length-1; } + cursor.x = getCharPosition(cursor.y, e.x - xOffset); cursor.lastX = cursor.x; - if (cursor.x > buf.lines[cursor.y].length) { - cursor.x = cast(int) buf.lines[cursor.y].length; - } } else if (e.key == Key.ctrlS) { if (buf.path != "") { buf.save();