Implement Undo / Redo in TextArea

I am wondering how to implement the undo of Redo functionality using TextArea. I already have the functionality without support, now I have two questions.

  • When I start / stop a new cancel / redo command, for example, when the user hits, how far back I go.
  • How to implement this (1.) in regular TextArea

My thinking: I think I should create a new cancellation command when something other than a letter + space is hit. For this, I would use the keyDown event and check if the key is alpha-num if it is not reset by a command.

Sounds good?

+3
source share
3 answers

keydown , (//).

, , "change" ( , ), ( "" "htmlText", ) undo-buffer ( ). , (, , ).

, / ( ) .

"" , .

+2

1. / /, , , .

, ? , (, Paint.NET) . .

+1

1.) Event.CHANGE TextField . : . TextField , - .

2.) Memento Pattern. , . : undo() redo(). undo() textField.text = oldContent redo() textField.text = newContent. .

3.) . Event.CHANGE, CHANGE, FOCUS_OUT TextField. TextField. TextField , . TextField FOCUS_OUT:)

+1
source

Source: https://habr.com/ru/post/1724465/


All Articles