From d81bb611b6f6f44a680af15c8d787b5a0c946643 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 20 Feb 2019 17:30:36 +0000 Subject: [PATCH] Bug 17179: Add keyboard shortcuts to repeat (duplicate) a field, and cut text This patchset introduces an internal clipboard to the advanced editor and provides some new functionality to make use of this, default shortcuts are provided but can be edited per bug 21411 The default shortcuts for new/changed functions are: Changed: Ctrl-X: Now cuts a line into the clipboard area Shift-Ctrl-X: Now cuts current subfield into clipboard area Added: Ctrl-C: Copies a line into the clipboard area Shift-Ctrl-C: Copies current subfield into clipboard area Ctrl-P: Pastes the selected item from the clipboard at cursor Ctrl-I: Copies the current line and inserts onto a new line below To test: Verify all functionality above and confirm it behaves as expected Note: Ctrl-v pastes from the system clipboard - codemirror does not have access and this is why we use our "Clipboard" For browser cut/paste please use mouse right click or context menus Ctrl-P can be accessed as print by focusing outside the editor window --- .../bug_17179_add_keyboard_shortcuts.perl | 13 ++++++ .../data/mysql/en/mandatory/keyboard_shortcuts.sql | 4 ++ .../lib/koha/cateditor/marc-editor.js | 48 +++++++++++++++++++++- .../prog/en/modules/cataloguing/editor.tt | 6 +++ 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_17179_add_keyboard_shortcuts.perl diff --git a/installer/data/mysql/atomicupdate/bug_17179_add_keyboard_shortcuts.perl b/installer/data/mysql/atomicupdate/bug_17179_add_keyboard_shortcuts.perl new file mode 100644 index 0000000000..94c68a5ba6 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_17179_add_keyboard_shortcuts.perl @@ -0,0 +1,13 @@ +$DBversion = 'XXX'; +if( CheckVersion( $DBversion ) ) { + $dbh->do(q| + INSERT IGNORE INTO keyboard_shortcuts (shortcut_name, shortcut_keys, shortcut_desc) VALUES + ("copy_line","Ctrl-C","Copy current field"), + ("copy_subfield","Shift-Ctrl-C","Copy current subfield"), + ("paste_line","Ctrl-P","Paste selectiion from 'clipboard'"), + ("insert_line","Ctrl-I","Copy current field on next line") + ;| + ); + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 17179 - Add additional keyboard_shortcuts)\n"; +} diff --git a/installer/data/mysql/en/mandatory/keyboard_shortcuts.sql b/installer/data/mysql/en/mandatory/keyboard_shortcuts.sql index b7e30d3b73..7dca73893e 100644 --- a/installer/data/mysql/en/mandatory/keyboard_shortcuts.sql +++ b/installer/data/mysql/en/mandatory/keyboard_shortcuts.sql @@ -25,6 +25,10 @@ INSERT INTO keyboard_shortcuts (shortcut_name, shortcut_keys, shortcut_desc) VAL ("insert_copyright","Alt-C","Insert copyright symbol (©)"), ("insert_copyright_sound","Alt-P","Insert copyright symbol (℗) (sound recordings)"), ("insert_delimiter","Ctrl-D","Insert delimiter (‡)"), + ("copy_line","Ctrl-C","Copy current field"), + ("copy_subfield","Ctrl-Shift-C","Copy current subfield"), + ("paste_line","Ctrl-P","Paste selectiion from 'clipboard'"), + ("insert_line","Ctrl-I","Copy current field on next line"), ("subfield_help","Ctrl-H","Get help on current subfield"), ("link_authorities","Shift-Ctrl-L","Link field to authorities"), ("delete_field","Ctrl-X","Delete current field"), diff --git a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-editor.js b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-editor.js index af20307ca2..a674b738f9 100644 --- a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-editor.js +++ b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-editor.js @@ -160,6 +160,9 @@ define( [ 'marc-record', 'koha-backend', 'preferences', 'text-marc', 'widget' ], _editorKeys[delete_field] = function( cm ) { // Delete line (or cut) if ( cm.somethingSelected() ) return true; + var curLine = cm.getLine( cm.getCursor().line ); + + $("#clipboard").prepend(''); cm.execCommand('deleteLine'); } @@ -193,8 +196,49 @@ define( [ 'marc-record', 'koha-backend', 'preferences', 'text-marc', 'widget' ], var field = cm.marceditor.getCurrentField(); if ( !field ) return; - var subfield = field.getSubfieldAt( cm.getCursor().ch ); - if ( subfield ) subfield.delete(); + var curCursor = cm.getCursor(); + var subfield = field.getSubfieldAt( curCursor().ch ); + var subfieldText= cm.getRange({line:curCursor.line,ch:subfield.start},{line:curCursor.line,ch:subfield.end}); + if ( subfield ) { + $("#clipboard").prepend(''); + subfield.delete(); + } + } + + _editorKeys[copy_line] = function( cm ) { + // Copy line + if ( cm.somethingSelected() ) return true; + var curLine = cm.getLine( cm.getCursor().line ); + $("#clipboard").prepend(''); + } + + _editorKeys[copy_subfield] = function( cm ) { + // Copy subfield + var field = cm.marceditor.getCurrentField(); + if ( !field ) return; + + var curCursor = cm.getCursor(); + var subfield = field.getSubfieldAt( curCursor().ch ); + var subfieldText= cm.getRange({line:curCursor.line,ch:subfield.start},{line:curCursor.line,ch:subfield.end}); + if ( subfield ) { + $("#clipboard").prepend(''); + } + } + + _editorKeys[paste_line] = function( cm ) { + // Paste line from "clipboard" + if ( cm.somethingSelected() ) return true; + var cBoard = document.getElementById("clipboard"); + var strUser = cBoard.options[cBoard.selectedIndex].text; + cm.replaceRange( strUser, cm.getCursor(), null ); + } + + _editorKeys[insert_line] = function( cm ) { + // Copy line and insert below + if ( cm.somethingSelected() ) return true; + var curLine = cm.getLine( cm.getCursor().line ); + cm.execCommand('newlineAndIndent'); + cm.replaceRange( curLine, cm.getCursor(), null ); } _editorKeys[next_position] = function( cm ) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt index 928190498f..9f2f536a40 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt @@ -108,6 +108,12 @@ +

Clipboard

+
+ +
+ -- 2.11.0