nnhubbard / ZSSRichTextEditor

A beautiful rich text WYSIWYG editor for iOS with a syntax highlighted source view
MIT License
3.78k stars 584 forks source link

question about 'undo' #247

Open Jacky-LinPeng opened 4 years ago

Jacky-LinPeng commented 4 years ago

how to cancle the text from last edit word not cancle all edit word

YoomamaFTW commented 4 years ago

My repository for RichEditorView most likely does the same thing. We use a JavaScript command called execCommand in which the browser decides what is undone. The command, itself, is most likely: document.execCommand('undo', false, null);

I'm not too sure since I don't use this repo, but it most likely does this. There really isn't much leeway unless you use a DispatchQueue like so (this is pseudocode since I don't use this repository):

override func viewDidLoad() {
    super.viewDidLoad()
    getLastContent()
}
var undo_html = ""
private func getLastContent() {
    DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
        undo_html = self.editorView.get_html()  // Assuming the editor controller is editorView
        self.getLastContent()  // Recursive
    }
}

Then you can rewrite the undo functionality by using that variable undo_html instead by setting the html to that for undo. Best have a redo variable in that case, as well, since you're technically changing the text, not undoing.