Bug 11559: (followup) fix first-character deletion, small usability issues
authorJesse Weaver <pianohacker@gmail.com>
Mon, 19 Oct 2015 23:47:13 +0000 (17:47 -0600)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 27 Oct 2015 15:18:00 +0000 (12:18 -0300)
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 <nick@quecheelibrary.org>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
koha-tmpl/intranet-tmpl/lib/koha/cateditor/marc-editor.js
koha-tmpl/intranet-tmpl/lib/koha/cateditor/text-marc.js
koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js

index 3ccb284..91a286d 100644 (file)
@@ -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 } );
         },
index b8226ec..0440a99 100644 (file)
@@ -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;
index ec03ecf..7ea3fc8 100644 (file)
@@ -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();
                     }
                 }