diff --git a/src/dlangui/core/editable.d b/src/dlangui/core/editable.d index 7ae35784..bfa8af03 100644 --- a/src/dlangui/core/editable.d +++ b/src/dlangui/core/editable.d @@ -458,6 +458,7 @@ class EditableContent { /// call listener to say that whole content is replaced e.g. by loading from file void notifyContentReplaced() { + clearEditMarks(); TextRange rangeBefore; TextRange rangeAfter; // notify about content change @@ -532,6 +533,7 @@ class EditableContent { /// clear content void clear() { clearUndo(); + clearEditMarks(); _lines.length = 0; } @@ -704,7 +706,7 @@ class EditableContent { } /// inserts or removes lines, removes text in range - protected void replaceRange(TextRange before, TextRange after, dstring[] newContent) { + protected void replaceRange(TextRange before, TextRange after, dstring[] newContent, EditStateMark[] marks = null) { dstring firstLineBefore = line(before.start.line); dstring lastLineBefore = before.singleLine ? firstLineBefore : line(before.end.line); dstring firstLineHead = before.start.pos > 0 && before.start.pos <= firstLineBefore.length ? firstLineBefore[0..before.start.pos] : ""d; @@ -720,6 +722,10 @@ class EditableContent { removeLines(before.start.line + 1, linesBefore - linesAfter); } for (int i = after.start.line; i <= after.end.line; i++) { + if (marks) { + if (i - after.start.line < marks.length) + _editMarks[i] = marks[i - after.start.line]; + } dstring newline = newContent[i - after.start.line]; if (i == after.start.line && i == after.end.line) { dchar[] buf; @@ -926,9 +932,10 @@ class EditableContent { TextRange rangeBefore = op.newRange; dstring[] oldcontent = op.content; dstring[] newcontent = op.oldContent; + EditStateMark[] newmarks = op.oldEditMarks; TextRange rangeAfter = op.range; //Log.d("Undoing op rangeBefore=", rangeBefore, " contentBefore=`", oldcontent, "` rangeAfter=", rangeAfter, " contentAfter=`", newcontent, "`"); - replaceRange(rangeBefore, rangeAfter, newcontent); + replaceRange(rangeBefore, rangeAfter, newcontent, newmarks); handleContentChange(op, rangeBefore, rangeAfter, this); return true; } diff --git a/src/dlangui/platforms/common/platform.d b/src/dlangui/platforms/common/platform.d index 3ce90e37..8f54a6fe 100644 --- a/src/dlangui/platforms/common/platform.d +++ b/src/dlangui/platforms/common/platform.d @@ -317,55 +317,59 @@ class Window { static immutable int PERFORMANCE_LOGGING_THRESHOLD_MS = 20; void onDraw(DrawBuf buf) { - bool needDraw = false; - bool needLayout = false; - bool animationActive = false; - checkUpdateNeeded(needDraw, needLayout, animationActive); - if (needLayout || animationActive) - needDraw = true; - long ts = std.datetime.Clock.currStdTime; - if (animationActive && lastDrawTs != 0) { - animate(ts - lastDrawTs); - // layout required flag could be changed during animate - check again + try { + bool needDraw = false; + bool needLayout = false; + bool animationActive = false; checkUpdateNeeded(needDraw, needLayout, animationActive); - } - lastDrawTs = ts; - if (needLayout) { - long measureStart = currentTimeMillis; - measure(); - long measureEnd = currentTimeMillis; - if (measureEnd - measureStart > PERFORMANCE_LOGGING_THRESHOLD_MS) { - debug(DebugRedraw) Log.d("measure took ", measureEnd - measureStart, " ms"); + if (needLayout || animationActive) + needDraw = true; + long ts = std.datetime.Clock.currStdTime; + if (animationActive && lastDrawTs != 0) { + animate(ts - lastDrawTs); + // layout required flag could be changed during animate - check again + checkUpdateNeeded(needDraw, needLayout, animationActive); } - layout(); - long layoutEnd = currentTimeMillis; - if (layoutEnd - measureEnd > PERFORMANCE_LOGGING_THRESHOLD_MS) { - debug(DebugRedraw) Log.d("layout took ", layoutEnd - measureEnd, " ms"); + lastDrawTs = ts; + if (needLayout) { + long measureStart = currentTimeMillis; + measure(); + long measureEnd = currentTimeMillis; + if (measureEnd - measureStart > PERFORMANCE_LOGGING_THRESHOLD_MS) { + debug(DebugRedraw) Log.d("measure took ", measureEnd - measureStart, " ms"); + } + layout(); + long layoutEnd = currentTimeMillis; + if (layoutEnd - measureEnd > PERFORMANCE_LOGGING_THRESHOLD_MS) { + debug(DebugRedraw) Log.d("layout took ", layoutEnd - measureEnd, " ms"); + } + //checkUpdateNeeded(needDraw, needLayout, animationActive); } - //checkUpdateNeeded(needDraw, needLayout, animationActive); - } - long drawStart = currentTimeMillis; - // draw main widget - _mainWidget.onDraw(buf); + long drawStart = currentTimeMillis; + // draw main widget + _mainWidget.onDraw(buf); - PopupWidget modal = modalPopup(); + PopupWidget modal = modalPopup(); - // draw popups - foreach(p; _popups) { - if (p is modal) { - // TODO: get shadow color from theme - buf.fillRect(Rect(0, 0, buf.width, buf.height), 0xD0404040); + // draw popups + foreach(p; _popups) { + if (p is modal) { + // TODO: get shadow color from theme + buf.fillRect(Rect(0, 0, buf.width, buf.height), 0xD0404040); + } + p.onDraw(buf); } - p.onDraw(buf); + long drawEnd = currentTimeMillis; + debug(DebugRedraw) { + if (drawEnd - drawStart > PERFORMANCE_LOGGING_THRESHOLD_MS) + Log.d("draw took ", drawEnd - drawStart, " ms"); + } + if (animationActive) + scheduleAnimation(); + _actionsUpdateRequested = false; + } catch (Exception e) { + Log.e("Exception inside winfow.onDraw: ", e); } - long drawEnd = currentTimeMillis; - debug(DebugRedraw) { - if (drawEnd - drawStart > PERFORMANCE_LOGGING_THRESHOLD_MS) - Log.d("draw took ", drawEnd - drawStart, " ms"); - } - if (animationActive) - scheduleAnimation(); - _actionsUpdateRequested = false; } /// after drawing, call to schedule redraw if animation is active diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index 0b2a437b..828d0d2e 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -196,8 +196,8 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction protected uint _leftPaneLineNumberColor = 0x4060D0; protected uint _leftPaneLineNumberBackgroundColor = 0xF0F0F0; protected uint _iconsPaneWidth = 16; - protected uint _foldingPaneWidth = 16; - protected uint _modificationMarksPaneWidth = 8; + protected uint _foldingPaneWidth = 12; + protected uint _modificationMarksPaneWidth = 4; /// when true, call measureVisibileText on next layout protected bool _contentChanged = true; @@ -249,7 +249,7 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction buf.fillRect(rc, 0xFFD040); } else if (m == EditStateMark.saved) { // modified, not saved - buf.fillRect(rc, 0x80FF60); + buf.fillRect(rc, 0x20C020); } } }