RSyntaxTextArea icon indicating copy to clipboard operation
RSyntaxTextArea copied to clipboard

Improve undo/redo history and notifications about undo/redo actions

Open vinyanalista opened this issue 10 years ago • 0 comments

First of all, congratulations for your excellent work! I'm using RSyntaxTextArea on my bachelor's degree concluding project, to write an IDE for a custom programming language. I would like to suggest you a feature that would certainly improve RSyntaxTextArea and make it even more professional.

Let me take an advanced text editor (one with syntax highlighting capabilities) as example, so I can more easily show what I want. I like Kate, which I use on my Linux desktop.

When I open Kate, it starts with an empty document, Undo and Redo actions are disabled. If I start typing, the Undo action becomes available. The title bar warns me that the text has been modified. Let's suppose I then save the file. When I do that, the title bar hides the warning that the text has been modified. If I start typing again, the title bar warns me again about the file been modified. Until then, nothing new. I can implement this behavior on my application using RSyntaxTextArea.

But let's suppose I regret the last changes I've made since the text has been saved. I then click on the Undo button sufficient times so the text looks like now when I saved it. Kate realizes that I've restored the text to that content it had when I saved the file, and hides the warning about the text been modified. As I clicked Undo, the Redo action is now available. If I redo the changes, the warning is shown again. That behavior I can't implement on my application using RSyntaxTextArea.

The problem is that neither RSyntaxTextArea nor the classes it uses (like RTextArea and RUndoManager) let me know how many compound edits I did (or undid, or redid) after certain moment (for example, when I saved the file). It would be very nice if you could implement:

  1. a way for us, programmers using RSyntaxTextArea, to get notified about new edits, so we can update the application interface to notify the user about changes in the text; and
  2. a way for us, programmers using RSyntaxTextArea, to know how many edits we undid or redid after a certain edit in the undo/redo history.

I will think of something and propose a pull request, but I wanted to first register here what I thought. Maybe someone finds a solution to that problem before than me.

How I'm handling this problem right now

Right now, due to the limitations of the component explained above, my application is resetting the undo/redo history when the user saves the file. Let's see how it works.

The application starts with an empty text, both Undo and Redo actions starts disabled. If the user starts typing, the Undo action becomes available, and the title bar notifies the user that the text has changed. The user can type, undo and redo as he/she wants, the application behaves as expected. When the user asks the application to save the file, it saves the file and then clears the undo/redo history (through RSyntaxTextArea.discardAllEdits()), so the Undo and Redo actions become unavailable again (as they were when the user started the application) and the title bar removes the warning about the text been changed.

After saving the text, the user can start typing again, so the Undo action will become available again. The user can type, undo and redo as he/she wants, the application behaves as expected, except that he/she will be able to undo or redo only the edits made after the text has been saved. Supposing the text was not empty when it was saved, the user won't be able, for example, to make it empty again (as it was when the application was started) using Undo/Redo actions.

It's a simpler approach than Kate's, but it's not what most text editors do.

vinyanalista avatar Sep 07 '14 16:09 vinyanalista