From 77adfc73c190edb0a34d353c46aae84a2ba8f10a Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Mon, 4 Sep 2017 14:13:57 +0300 Subject: [PATCH] fix #246 - autoindent issues --- dub.json | 2 +- src/dlangide/tools/d/dsyntax.d | 17 +++++++++++++++-- views/VERSION | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/dub.json b/dub.json index 7519421..d649616 100644 --- a/dub.json +++ b/dub.json @@ -12,7 +12,7 @@ "stringImportPaths": ["views", "views/res", "views/res/i18n", "views/res/mdpi", "views/res/hdpi"], "dependencies": { - "dlangui": "==0.9.107", + "dlangui": "==0.9.108", "dcd": "~>0.9.1" }, diff --git a/src/dlangide/tools/d/dsyntax.d b/src/dlangide/tools/d/dsyntax.d index bdcad07..b2d91ed 100644 --- a/src/dlangide/tools/d/dsyntax.d +++ b/src/dlangide/tools/d/dsyntax.d @@ -653,11 +653,15 @@ class SimpleDSyntaxSupport : SyntaxSupport { dstring lineText = _content.line(line); TextLineMeasure lineMeasurement = _content.measureLine(line); TextLineMeasure prevLineMeasurement = _content.measureLine(prevLine); + bool prevLineSpaceOnly = false; + if (prevLineMeasurement.empty && prevLineMeasurement.len) { + prevLineSpaceOnly = true; + } while (prevLineMeasurement.empty && prevLine > 0) { prevLine--; prevLineMeasurement = _content.measureLine(prevLine); } - if (lineMeasurement.firstNonSpaceX >= 0 && lineMeasurement.firstNonSpaceX < prevLineMeasurement.firstNonSpaceX) { + if (lineMeasurement.firstNonSpaceX >= 0 && lineMeasurement.firstNonSpaceX <= prevLineMeasurement.firstNonSpaceX) { dstring prevLineText = _content.line(prevLine); TokenPropString prevLineTokenProps = _content.lineTokenProps(prevLine); dchar lastOpChar = 0; @@ -674,7 +678,16 @@ class SimpleDSyntaxSupport : SyntaxSupport { if (lastOpChar == '{') spacex = _content.nextTab(spacex); dstring txt = _content.fillSpace(spacex); - EditOperation op2 = new EditOperation(EditAction.Replace, TextRange(TextPosition(line, 0), TextPosition(line, lineMeasurement.firstNonSpace >= 0 ? lineMeasurement.firstNonSpace : 0)), [txt]); + dstring[] newContent; + auto startPos = TextPosition(line, 0); + auto endPos = TextPosition(line, lineMeasurement.firstNonSpace >= 0 ? lineMeasurement.firstNonSpace : 0); + if (prevLineSpaceOnly) { + // clear spaces from previous line + startPos.line--; + newContent ~= ""d; + } + newContent ~= txt; + EditOperation op2 = new EditOperation(EditAction.Replace, TextRange(startPos, endPos), newContent); _opInProgress = true; _content.performOperation(op2, source); _opInProgress = false; diff --git a/views/VERSION b/views/VERSION index 7d89f1b..6c68d7c 100644 --- a/views/VERSION +++ b/views/VERSION @@ -1 +1 @@ -v0.7.61 \ No newline at end of file +v0.7.62 \ No newline at end of file