Skip to content

Commit

Permalink
Fix redo
Browse files Browse the repository at this point in the history
  • Loading branch information
callumenator committed Jul 1, 2013
1 parent 1fd8451 commit e1f7be8
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/glui/widget/textutil.d
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ class STextArea : TextArea
*/
override void insert(string s)
{
if (s.length == 0)
return;

auto preCaret = caret;
if (s.length == 1 && s[0] == '\n')
{
Expand Down Expand Up @@ -288,7 +291,7 @@ class STextArea : TextArea
}

if (!undoing)
undoStack.push(Change(Change.Type.insert, preCaret, caret, ""));
undoStack.push(Change(Change.Type.insert, preCaret, caret, s));
}

/**
Expand Down Expand Up @@ -407,7 +410,7 @@ class STextArea : TextArea
saveColumn();

if (!undoing)
undoStack.push(Change(Change.Type.remove, start, start, deleted));
undoStack.push(Change(Change.Type.remove, start, end, deleted));

return deleted;
}
Expand Down Expand Up @@ -783,18 +786,31 @@ class STextArea : TextArea
{
remove(action.caretStart, action.caretEnd);
}
else
else if (action.type == Change.Type.remove)
{
caret = action.caretStart;
insert(action.data);
}
redoStack.push(action);
undoing = false;
}

override void redo()
{
if (redoStack.empty)
return;

auto action = redoStack.pop();

if (action.type == Change.Type.remove)
{
remove(action.caretStart, action.caretEnd);
}
else if (action.type == Change.Type.insert)
{
caret = action.caretStart;
insert(action.data);
}
}

private:
Expand Down Expand Up @@ -891,7 +907,6 @@ struct UndoStack(T, size_t size)
used++;

_buffer[top] = item;
writeln(top);
}

T pop()
Expand Down

0 comments on commit e1f7be8

Please sign in to comment.