How to Clear the data of a cell after Ctrl+x to cut it and it still can undo

Posted by: timzod on 26 September 2018, 4:09 am EST

    • Post Options:
    • Link

    Posted 26 September 2018, 4:09 am EST

    Hi,

    Ctrl+x /Ctrl+v to cut A1 to B1 runs well in single file case, the data of A1 moved to B1 and then the A1 been set to empty.

    We have an requirement to CUT A1 cell of a.xlsx to B1 cell of b.xlsx , but the A1 does not be cleared after been pasted to B1.

    to solve this problem, after ctrl+x , i use GC.Spread.Sheets.designer.spreadActions.clearContent(spread) immediately to clear A1 before it pasted to another file , all these seems runs well.

    The problem is, when I return to a.xlsx and tried to Undo(Ctrl+Z) to rollback A1 to previous status, the A1 still be empty undo failed, i guess the Action.clearContent() does not be pushed to the stack of undoManager.

    Anyone can tell me how to clear the cell and can undo the clear action through Ctrl+Z.

    Or tell me how to simulate an keyDown event(delete) for A1 cell.

    Thanks very much!

    Open two instance of below url can recreate it.

    https://www.grapecity.com/en/demos/spread/JS/InspectorSample/

  • Posted 28 September 2018, 7:38 am EST

    Hello,

    You can capture Ctrl+X key on keyDown event and execute the clearValues internal command for the same as given in attached sample.

        $(document).keydown(function (e) {
                    if (e.keyCode == 88 && e.ctrlKey) {
                        spread.options.allowUndo = true;
                        spread.commandManager().execute({ cmd: "clearValues", sheetName: "Sheet1", ranges: [new GC.Spread.Sheets.Range(0, 0, 2, 2)] });
                    }
                });
    
    

    Hope it helps.

    Thanks,

    Reeva

    Undo_CutPaste_V11SP2.zip

  • Posted 28 September 2018, 10:30 pm EST

    thank you reeva, now the undo function works well.

    but the Ctrl+V seems not work when I try to CUT the whole row and try to paste to another row.

    while ctrl+C a row/Ctrl+V works, ctrl+X cells/ctrl+V works.

    step to recreate:

    1.Ctrl+X the whole first row in your sample

    2.select row5 and type Ctrl+V

    3. nohting happened

    Thanks

  • Posted 1 October 2018, 1:57 am EST

    Hello,

    I have modified the code in my sample to make it work. Please have a look at attached sample and code for the same:-

    var sels = activeSheet.getSelections();
    spread.commandManager().execute({ cmd: "clearValues", sheetName: "Sheet1", ranges: [new GC.Spread.Sheets.Range(sels.row, sels.col, sels.rowCount, sels.colCount)] });
    

    Hope it helps.

    Thanks,

    Reeva

    Undo_CutPaste_V11SP2_modified.zip

  • Posted 8 October 2018, 5:09 am EST

    Hello Reeva,

    I tried the updated code with Firefox47 and Chrome69.

    Yes, I can use Ctrl+Z after CUT a whole row, but it seems that the cell data did not been cleared after Ctrl+X.

    I find that the code should change from

    ranges: [new GC.Spread.Sheets.Range(sels.row, sels.col, sels.rowCount, sels.colCount)] }
    

    to ```

    ranges: [new GC.Spread.Sheets.Range(sels[0].row, sels[0].col, sels[0].rowCount, sels[0].colCount)] }

    
    The upper modification can clear the cell after Ctrl+X  , but still could not paste with Ctrl+V if I CUT  a whole row/column.
    
    Thanks a lot.
  • Posted 10 October 2018, 1:52 am EST

    Hello timzod,

    Unfortunately, I am unable to replicate the issue with the sample I gave you using Firefox62 and Chrome69 using SpreadJs version 11.2.6

    We followed these steps:-

    1. Select row 1> Ctrl+X
    2. Select row 5> Ctrl+V

    Working fine, even Ctrl+Z after this is working fine as it removes pasted values

    1. Select cells A5&B5 > Ctrl +C
    2. Select any cell > Ctrl +V

    Working fine, even Ctrl+Z after this is working fine as it removes pasted values

    1. Insert Data in cells of row 2
    2. Select row 2> Ctrl+C
    3. Select row 6> Ctrl+V

    Working fine, even Ctrl+Z after this is working fine as it removes pasted values

    Please let us know what steps are we missing to replicate the issue so that we can investigate this issue further.

    Thanks,

    Reeva

  • Posted 10 October 2018, 2:37 am EST - Updated 3 October 2022, 11:06 am EST

    Hi Reeva,

    below are my steps based on your latest attachment

    1)Select row1 > Ctrl +X

    (in my previous post, i wish the content be cleared just after ctrl+X, no matter whether paste or not later on, but the row1 content still there ,please take a look on screenshot)

    2)Select row5 > Ctrl+ V

    (paste fine and so does Ctrl+z , the content of row1 was cleared only after Ctrl+V )

    Thanks a lot!

  • Posted 17 October 2018, 11:06 am EST

    Hello,

    If you clear the values of the cells as soon as you hit the Ctrl+X then no data will be pasted on Ctrl+V.

    To achieve the behavior you are looking for, you would need to handle the copy paste in code completely

    For example, you would need to get the cell/s value on Ctrl+X and then set it for for the selected cell/s on Ctrl + V:

    
     <script type="text/javascript">       
                var spread, sheet, r, c, rcount, ccount;
                var ctrlX, txt;
                $(document).ready(function () {
                    spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"),{sheetCount:3});
                    sheet = spread.sheets[0];
                    sheet.setFormula(1,1,"SUM(Sheet2!C1:D1)",GC.Spread.Sheets.SheetArea.viewport);
                    var sheet2 = spread.sheets[1];
                    sheet2.setValue(0, 2, "2", GC.Spread.Sheets.SheetArea.viewport);
                    sheet2.setValue(0, 3, "2", GC.Spread.Sheets.SheetArea.viewport);
    
    
    			spread.commandManager().register('ctrlXKeyPress', function () {
    			//get cell value here
    			});
    			spread.commandManager().register('ctrlVKeyPress', function () {
    			//set cell value here
    			});
    			spread.commandManager().setShortcutKey("ctrlVKeyPress", GC.Spread.Commands.Key.v, true, false, false, false);
    			spread.commandManager().setShortcutKey('ctrlXKeyPress', GC.Spread.Commands.Key.x, true, false, false, false);
             
                });
        </script>
    
    

    Thanks,

    Deepak Sharma

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels