From 3e5e51935809d145b168b137792b6d32f0632b1a Mon Sep 17 00:00:00 2001 From: Jesse Weaver Date: Mon, 19 Oct 2015 17:47:13 -0600 Subject: [PATCH] Bug 11559: (followup) fix first-character deletion, small usability issues This should fix the first-character deletion bug reported by Nick, and also: * Fix subfield deletion * Attempted fix for special keys on dropdowns * Allow deleting empty fields * Fix bug with composed characters --- koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-editor.js | 6 ++++-- koha-tmpl/intranet-tmpl/lib/koha/cateditor/text-marc.js | 2 +- koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js | 12 +++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) 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 3ccb284..91a286d 100644 --- a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-editor.js +++ b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-editor.js @@ -152,8 +152,7 @@ define( [ 'marc-record', 'koha-backend', 'preferences', 'text-marc', 'widget' ], // Delete line (or cut) if ( cm.somethingSelected() ) return true; - var field = cm.marceditor.getCurrentField(); - if ( field ) field.delete(); + cm.execCommand('deleteLine'); }, 'Shift-Ctrl-X': function( cm ) { @@ -272,6 +271,9 @@ define( [ 'marc-record', 'koha-backend', 'preferences', 'text-marc', 'widget' ], return this.field._subfieldsInvalid(); }, + delete: function() { + this.cm.replaceRange( "", { line: this.field.line, ch: this.start }, { line: this.field.line, ch: this.end }, 'marcAware' ); + }, focus: function() { this.cm.setCursor( { line: this.field.line, ch: this.contentsStart } ); }, diff --git a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/text-marc.js b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/text-marc.js index b8226ec..0440a99 100644 --- a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/text-marc.js +++ b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/text-marc.js @@ -88,7 +88,7 @@ define( [ 'marc-record' ], function( MARC ) { $.each( subfields, function( i, subfield ) { var next = subfields[ i + 1 ]; - field.addSubfield( [ subfield.code, line.substring( subfield.ch + 3, next ? next.ch : line.length ) ] ); + field.addSubfield( [ subfield.code, line.substring( subfield.ch + 2, next ? next.ch : line.length ) ] ); } ); field.sourceLine = i; diff --git a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js index ec03ecf..7ea3fc8 100644 --- a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js +++ b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js @@ -169,7 +169,13 @@ define( [ 'resources' ], function( Resources ) { $inputs.each( function( i ) { $(this).on( 'keydown.marc-tab', function( e ) { - if ( e.which != 9 ) return; // Tab + // Cheap hack to disable backspace and special keys + if ( ( this.nodeName.toLowerCase() == 'select' && e.which == 9 ) || e.ctrlKey ) { + e.preventDefault(); + return; + } else if ( e.which != 9 ) { // Tab + return; + } var span = widget.mark.find(); var cur = editor.cm.getCursor(); @@ -210,7 +216,7 @@ define( [ 'resources' ], function( Resources ) { ActivateAt: function( editor, cur, idx ) { var marks = editor.findMarksAt( cur ); - if ( !marks.length ) return false; + if ( !marks.length || !marks[0].widget ) return false; var $input = $(marks[0].widget.node).find('input, select').eq(idx || 0); if ( !$input.length ) return false; @@ -264,7 +270,7 @@ define( [ 'resources' ], function( Resources ) { if ( marks.length ) { if ( marks[0].id == id ) { return; - } else { + } else if ( marks[0].widget ) { marks[0].widget.clearToText(); } } -- 2.6.1