From 3b2d66cec899dd3b33f41041bafb785bda7e1e31 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 Signed-off-by: Nick Clemens Signed-off-by: Katrin Fischer --- .../intranet-tmpl/lib/koha/cateditor/marc-editor.js | 6 ++++-- .../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 3ccb284a9f..91a286d9a7 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 b8226ec56d..0440a99822 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 ec03ecfe42..7ea3fc8489 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.39.5