Author Topic: UNDO and macros  (Read 1385 times)

jporkkahtc

  • Senior Community Member
  • Posts: 1783
  • Hero Points: 174
  • Text
UNDO and macros
« on: July 22, 2016, 11:12:29 pm »


Does undo/redo not work in macros?
"_undo('S')" says "Starts a new level of undo"
What are undo levels?


What I was really looking for was a way to make hl_word() from QuickHighlight, not participate in Undos ... I don't want undo/redo to undo a highlight to redo a highlight. (It calls _SetTextColor() to do the coloring).


When the highlight is undone, the highlight is removed from the current file, but QuickHighlight doesn't know this and the next time it refreshes the highlights it will get restored.


So even if hl_word should participate in undos, it would need to be a bit smarter and remove the highlight from the array of current highlights that it keeps.


   




I ended up with this mostly unrelated bug / question...




I did a macro recording with a mix of edits, undos and redos.


When I restart slick (clearing any undo history), then start with the same file and play back the macro I get a much different result.


I started with this file:
the
quick
brown
fox
jumped
over
the
lazy
dog


Then I moved to the end, added lines a,b,c,d,e,f,g.
Then I did some undos and redos.
The result was:
TOP LINE.
the
quick
brown
fox
jumped
over
the
lazy
dog
a
b
c
d
e
f
g
h
LAST LINE.




When I revert the file and play the macro, I get prompted to undo-past-save several times, and the result is:


TOP LINE.
the
quick
brown
fox
jumped
over
the
lazy
dog


f
g
h
DONE LAST LINE.






Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4791
  • Hero Points: 388
Re: UNDO and macros
« Reply #1 on: July 23, 2016, 01:20:46 am »
Roughly, before a command is executed, a new undo level is automatically added. A complete undo step is whatever happen between starts. If you want a single command to require multiple undo steps to undo (there are interesting reasons to do this), then use _undo('s').

DO NOT try to temporarily turn off undo and turn it back on so that some undo information does not get added. This just doesn't work.

As for QuickHighlight, it sounds like the way it was written, it's markup is undoable. It is possible to add color markup and have it not be undoable. However, it is not possible when using _SetTextColor() which uses a default stream marker type which specifies the UNDO flag.

I'm not familiar with what QuickHighlight so it's hard for me to know what would be the best method.

Mixing undos and redos when recording a macro doesn't work. We should probably display a message box and optionally cancel recording. The problem as you've already figured out is that playback will be broken.

jporkkahtc

  • Senior Community Member
  • Posts: 1783
  • Hero Points: 174
  • Text
Re: UNDO and macros
« Reply #2 on: July 23, 2016, 01:34:23 am »

QuickHighlight.e was posted here: http://community.slickedit.com/index.php?topic=4151.0


But basically, it does a search for the string to highlight, and calls _SetTextColor.
How else can color markups be applied?
StreamMarkers ?

    while (res == 0 && endlessLimit > 0) {
        _SetTextColor(color, word_len);
        res = repeat_search();
        --endlessLimit;
        ++matchCount;

« Last Edit: July 23, 2016, 01:37:36 am by Clark »

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 4791
  • Hero Points: 388
Re: UNDO and macros
« Reply #3 on: July 23, 2016, 01:43:08 am »
_SetTextColor just uses stream markers under the covers. We usually use stream markers in our macros but we do ship some code which uses _SetTextColor() (like for search results).

At the bottom of mouse.e, there's some stream marker test code (#if zeroed). I use it sometimes for testing stream marker code with various options. There should also be examples of calls to _StreamMarkerAdd() all over the macro source.