From 2672a3ea3b322e832dd6decf838690fd35862453 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 Signed-off-by: Alex Sassmannshausen --- .../bug_17179_add_keyboard_shortcuts.perl | 13 ++++++ .../lib/koha/cateditor/marc-editor.js | 48 +++++++++++++++++++++- .../prog/en/includes/keyboard_shortcuts.inc | 8 +++- .../prog/en/modules/cataloguing/editor.tt | 5 +++ 4 files changed, 70 insertions(+), 4 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..86c536f79a --- /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) VALUES + ("copy_line","Ctrl-C"), + ("copy_subfield","Shift-Ctrl-C"), + ("paste_line","Ctrl-P"), + ("insert_line","Ctrl-I") + ; + |); + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 17179 - Add additional keyboard_shortcuts)\n"; +} 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 4db3b8ae08..d3528eae88 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/includes/keyboard_shortcuts.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/keyboard_shortcuts.inc index e735300fdf..38b5abb24a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/keyboard_shortcuts.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/keyboard_shortcuts.inc @@ -5,12 +5,16 @@ [%- CASE 'insert_delimiter' -%]Insert delimiter (‡) [%- CASE 'subfield_help' -%]Get help on current subfield [%- CASE 'link_authorities' -%]Link field to authorities - [%- CASE 'delete_field' -%]Delete current field - [%- CASE 'delete_subfield' -%]Delete current subfield + [%- CASE 'delete_field' -%]Delete current field and copy to 'clipboard' + [%- CASE 'delete_subfield' -%]Delete current subfield and copy to 'clipboard' [%- CASE 'new_line' -%]New field on next line [%- CASE 'line_break' -%]Insert line break [%- CASE 'next_position' -%]Move to next position [%- CASE 'prev_position' -%]Move to previous position [%- CASE 'toggle_keyboard' -%]Toggle Keyboard + [%- CASE 'copy_line' -%]Copy current field + [%- CASE 'copy_subfield' -%]Copy current subfield + [%- CASE 'paste_line' -%]Paste selection from 'clipboard' + [%- CASE 'insert_line' -%]Copy current field on next line [%- END -%] [%- END -%] 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 c72bc92bdb..f75fee2e9d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/editor.tt @@ -109,6 +109,11 @@
  • Advanced »
  • +

    Clipboard

    +
    + +
    -- 2.11.0