From ce820a5dd25a8407ad581c217a011d75a02753f8 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Tue, 24 Feb 2015 14:13:41 +0300 Subject: [PATCH] support of smart indents --- src/dlangui/core/editable.d | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/dlangui/core/editable.d b/src/dlangui/core/editable.d index 7a7da7ae..f0fa1002 100644 --- a/src/dlangui/core/editable.d +++ b/src/dlangui/core/editable.d @@ -857,6 +857,31 @@ class EditableContent { return TextRange(TextPosition(lineIndex, 0), lineIndex < _lines.length - 1 ? lineBegin(lineIndex + 1) : lineEnd(lineIndex)); } + /// find nearest next tab position + int nextTab(int pos) { + return (pos + tabSize) / tabSize * tabSize; + } + + /// returns spaces/tabs for filling from the beginning of line to specified position + dstring fillSpace(int pos) { + dchar[] buf; + int x = 0; + while (x + tabSize <= pos) { + if (useSpacesForTabs) { + for (int i = 0; i < tabSize; i++) + buf ~= ' '; + } else { + buf ~= '\t'; + } + x += tabSize; + } + while (x < pos) { + buf ~= ' '; + x++; + } + return cast(dstring)buf; + } + /// measures line non-space start and end positions TextLineMeasure measureLine(int lineIndex) { TextLineMeasure res;