Author Topic: cursor movements caused the loss of the redo history  (Read 16659 times)

Stu

  • Community Member
  • Posts: 59
  • Hero Points: 0
Re: cursor movements caused the loss of the redo history
« Reply #15 on: June 16, 2011, 03:58:30 PM »
maybe it should be as simple as dont commit cursor movement to the undo stack until a physical change in file is made. once another action is performed, then commit preceeding cursor actions.


chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: cursor movements caused the loss of the redo history
« Reply #16 on: July 18, 2011, 08:05:19 AM »
Bump.  Whenever I really need Redo, it doesn't actually work because SE is so aggressive about discarding the content Redo stack whenever any kind of movement occurs.  Even just clicking the mouse discards the content Redo stack.

This has forced me to try to change my workflow.  To be successful at that I have to remember ahead of time that SE discards the content Redo stack aggressively, before I hit Undo in the first place.  So what I do now is basically hit Save every couple of lines.  Which pollutes the SE backup history and reduces its effectiveness (sifting through 120 "revisions" from a single day to try to find something is awkward).

It's not uncommon for me to hold down Undo for a bit, accidentally overshoot where I meant to go, but need to move the cursor to be able to detect that I overshot.  And once I've done that there's nothing I can do about having overshot, the Redo stack is already gone.  If I'm lucky the SE backup history will have the changes I'm looking for, but it's cumbersome to try to find what I'm looking for that way (because the lack of Redo has made me save every couple of lines).  I end up using Save As, then open several backup files and Save As each of them to temp files, then close SE without saving (saving could potentially nuke the only copy of the text and force me to reinvent it).  Then I use other tools to compare the several files and extract the bits I need and use another editor to get the file to have the right content again.  Then I launch SE again and continue.

It's not the highest priority, but it's a bit of an "in your face" fit and finish item.  Hopefully it can be addressed before too long.

Graeme

  • Senior Community Member
  • Posts: 2793
  • Hero Points: 347
Re: cursor movements caused the loss of the redo history
« Reply #17 on: July 20, 2011, 11:11:27 AM »

This has forced me to try to change my workflow.  To be successful at that I have to remember ahead of time that SE discards the content Redo stack aggressively, before I hit Undo in the first place.  So what I do now is basically hit Save every couple of lines.  Which pollutes the SE backup history and reduces its effectiveness (sifting through 120 "revisions" from a single day to try to find something is awkward).

Dunno if this is any use but your post reminded me that when this problem came up a year ago I fiddled round with trying to use backup history as a solution too.  At the time I gave up and didn't post the code but I can't remember what the problem was.  I just tried it in V16 and it sort of seems to work.

The idea is to use x_undo and x_redo instead of undo redo.  x_undo switches the backup location, saves the file, restores the backup location before calling undo.    If x_redo finds nothing to redo it fires up backup history but with the alternate backup location selected.  You can left click in the bottom pane of the backup history window to switch backup locations.

I definitely don't recommend using this, it's very clunky.  I'm just posting it in case it gives you an idea.



Code: [Select]
#include "slick.sh"

#pragma option(strictsemicolons,on)
#pragma option(strict,on)
#pragma option(autodecl,off)
#pragma option(strictparens,on)

#import "tagform.e"
 
 


#define UNDO_BACKUP_FOLDER 'C:/gp/dev/temp1/b1'

// non static allows inspection with set-var
_str my_normal_backup_folder;
int x_redo_timer_handle;
int x_undo_timer_handle;
int x_undo_holdoff_counter;
int x_redo_holdoff_counter;

/**
 * Writes current buffer to filename.  This function is a hook function
 * that the user may replace.  Options allowed by <b>_save_file</b>
 * built-in may be specified.
 * @param filename parameter should not contain options.
 *
 * @appliesTo Edit_Window
 *
 * @categories File_Functions
 *
 */
_str save_file(_str filename,_str options)
{
   boolean was_undo = false;
   // the following 3 lines are added to handle x_redo
   _str vb = get_env('VSLICKBACKUP');
   if (vb == UNDO_BACKUP_FOLDER) {
      set_env('VSLICKBACKUP', my_normal_backup_folder );
      was_undo = true;
   }
   say(vb);

   typeless status=_save_file(options " "filename);
   if (!status && file_eq(strip(filename,'B','"'),p_buf_name)) {
      call_list('_cbsave_');
      if (def_autotag_flags2&AUTOTAG_ON_SAVE) {
         TagFileOnSave();
      }
   }
   if (was_undo && _tbIsVisible('_tbdeltasave_form')) {
      set_env('VSLICKBACKUP', UNDO_BACKUP_FOLDER );
   }
   return(status);
}


static int x_redo_holdoff_counter;

void x_redo_timer_callback(boolean force_normal = false)
{
   if (x_redo_holdoff_counter > 0) {
      say(' kk4 ' :+ x_redo_holdoff_counter);
      --x_redo_holdoff_counter;
      return;
   }
   _str vb = get_env('VSLICKBACKUP');
   if (vb != UNDO_BACKUP_FOLDER) {
      _kill_timer(x_redo_timer_handle);
      _cbsave_BackupHistory();  // force refresh
      return;
   }
   if (!_tbIsVisible('_tbdeltasave_form') || force_normal) {
      say(' kk5 ' :+ x_undo_holdoff_counter);
      set_env('VSLICKBACKUP', my_normal_backup_folder );
      _kill_timer(x_redo_timer_handle);
//    int wid = _find_formobj("_tbdeltasave_form", 'n');
//    if (wid) {
//       wid.p_caption = 'Backup History';
//    }
      _cbsave_BackupHistory();  // force refresh
      return;
   }
}



void x_undo_timer_callback()
{
   say(' kk1 ' :+ x_undo_holdoff_counter);
   if (--x_undo_holdoff_counter <= 0) {
      _kill_timer(x_undo_timer_handle);
   }
}


_command void x_undo() name_info(','VSARG2_MARK|VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL|VSARG2_LINEHEX/*|VSARG2_NOEXIT_SCROLL*/)
{
   if (x_undo_holdoff_counter > 0) {
      x_undo_holdoff_counter = 10; // seconds
      undo();
      x_redo_timer_callback(true);
      say(' kk2 ' :+ x_undo_holdoff_counter);
      return;
   }
   x_undo_holdoff_counter = 10; // seconds
   say(' kk3 ' :+ x_undo_holdoff_counter);
   set_env('VSLICKBACKUP', UNDO_BACKUP_FOLDER );
   _save_file(p_buf_name :+ ' -O +DD -Z -ZR -E -S -L ');
   set_env('VSLICKBACKUP', my_normal_backup_folder );
   undo();
   undo();
   x_undo_timer_handle = _set_timer(1000,x_undo_timer_callback);
   x_redo_timer_callback(true);
}


_command void x_redo() name_info(','VSARG2_MARK|VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL|VSARG2_LINEHEX)
{
   _control ctl_BH_comment_note2;
   x_redo_holdoff_counter = 2;
   if (redo() == NOTHING_TO_REDO_RC) {
      set_env('VSLICKBACKUP', UNDO_BACKUP_FOLDER );
      activate_deltasave();
      _cbsave_BackupHistory();  // force refresh
      x_redo_timer_handle = _set_timer(500,x_redo_timer_callback);
      int wid = _find_formobj("_tbdeltasave_form", 'n');
      if (wid) {
         //wid.p_caption = 'Backup History $$$$$  UNDO  $$$$$';
         wid.ctl_BH_comment_note2.p_text =
            '<FONT face="Helvetica" size="2"><b>$$$ UNDO HISTORY $$$</b><br>PATH: ' :+ UNDO_BACKUP_FOLDER ;
      }
   }
}


// 1 2

// 1 2 3
// 1 2
// 1 2 3
// 1x_redo
// 4 5

definit ()
{
   if (arg(1)!="L") {
      // editor invocation
      my_normal_backup_folder = get_env('VSLICKBACKUP');
      if (my_normal_backup_folder == '') {
         set_env('VSLICKBACKUP', 'C:/GP/Dev/temp1/B2');
         my_normal_backup_folder = 'C:/GP/Dev/temp1/B2';
      }
   }
   x_undo_holdoff_counter = 0;
   x_redo_holdoff_counter = 0;
}

defeventtab _tbdeltasave_form;
void ctl_BH_comment_note2.lbutton_down()
{
   _str vb = get_env('VSLICKBACKUP');
   if (vb != UNDO_BACKUP_FOLDER) {
      set_env('VSLICKBACKUP', UNDO_BACKUP_FOLDER );
      _cbsave_BackupHistory();  // force refresh
      int wid = _find_formobj("_tbdeltasave_form", 'n');
      if (wid) {
         //wid.p_caption = 'Backup History $$$$$  UNDO  $$$$$';
         wid.ctl_BH_comment_note2.p_text =
            '<FONT face="Helvetica" size="2"><b>$$$ UNDO HISTORY $$$</b><br>PATH: ' :+
            UNDO_BACKUP_FOLDER :+ '<br>Left click here to swap' ;
      }
   }
   else
   {
      set_env('VSLICKBACKUP', my_normal_backup_folder );
      _cbsave_BackupHistory();  // force refresh
   }
}