Changeset 1378


Ignore:
Timestamp:
02/06/18 11:47:27 (10 months ago)
Author:
gogo
Message:

Add improved and standardised tab handling support for Gecko and WebKit?, configurable by the tabSpanClass and tabSpanContents options.

Hitting tab will insert a span with the given class and contents, hitting more than once will insert nested tab spans, hitting shift-tab will remove the current tab span if you are in one, do nothing otherwise.

tested in FF and Chrome, it seems to work well.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/XinhaCore.js

    r1376 r1378  
    770770   */ 
    771771  this.specialReplacements = {}; //{ 'html_string' : 'wysiwyg_string' } 
     772   
     773  /** When the user presses the Tab in the editor, Xinha will insert a span. 
     774   *  with the given class and contents. 
     775   *  
     776   *  You can set tabSpanClass to false to disable this function, in which 
     777   *    case tabs will be disabled in Xinha (except for in lists if you load  
     778   *    the ListOperations plugin. 
     779   */ 
     780   
     781  this.tabSpanClass    = 'xinha-tab'; 
     782  this.tabSpanContents = '    '; 
    772783   
    773784  /** A filter function for the HTML used inside the editor<br /> 
  • trunk/modules/Gecko/Gecko.js

    r1312 r1378  
    203203    break; 
    204204     
     205    case 9: // KEY tab 
     206    { 
     207      // Note that the ListOperations plugin will handle tabs in list items and indent/outdent those 
     208      // at some point TableOperations might do also 
     209      // so this only has to handle a tab/untab in text 
     210      if(editor.config.tabSpanClass) 
     211      { 
     212        if(!ev.shiftKey) 
     213        { 
     214          editor.insertHTML('<span class="'+editor.config.tabSpanClass+'">'+editor.config.tabSpanContents+'</span>'); 
     215          var s = editor.getSelection().collapseToEnd(); 
     216        } 
     217        else 
     218        { 
     219          var existingTab = editor.getParentElement(); 
     220          if(existingTab && existingTab.className.match(editor.config.tabSpanClass)) 
     221          { 
     222            var s = editor.getSelection(); 
     223            s.removeAllRanges(); 
     224            var r = editor.createRange(); 
     225            r.selectNode(existingTab); 
     226            s.addRange(r); 
     227            s.deleteFromDocument(); 
     228          } 
     229        } 
     230      } 
     231       
     232      Xinha._stopEvent(ev); 
     233       
     234    } 
     235    break; 
     236     
    205237    case 8: // KEY backspace 
    206238    case 46: // KEY delete 
     
    212244      } 
    213245    } 
     246     
    214247     
    215248    default: 
  • trunk/modules/WebKit/WebKit.js

    r1336 r1378  
    187187    break; 
    188188     
     189    case 9: // KEY tab 
     190    { 
     191      // Note that the ListOperations plugin will handle tabs in list items and indent/outdent those 
     192      // at some point TableOperations might do also 
     193      // so this only has to handle a tab/untab in text 
     194      if(editor.config.tabSpanClass) 
     195      { 
     196        if(!ev.shiftKey) 
     197        { 
     198          editor.insertHTML('<span class="'+editor.config.tabSpanClass+'">'+editor.config.tabSpanContents+'</span>'); 
     199          var s = editor.getSelection().collapseToEnd(); 
     200        } 
     201        else 
     202        { 
     203          var existingTab = editor.getParentElement(); 
     204          if(existingTab && existingTab.className.match(editor.config.tabSpanClass)) 
     205          { 
     206            var s = editor.getSelection(); 
     207            s.removeAllRanges(); 
     208            var r = editor.createRange(); 
     209            r.selectNode(existingTab); 
     210            s.addRange(r); 
     211            s.deleteFromDocument(); 
     212          } 
     213        } 
     214      } 
     215       
     216      Xinha._stopEvent(ev); 
     217       
     218    } 
     219    break; 
     220     
    189221    case 8: // KEY backspace 
    190222    case 46: // KEY delete 
Note: See TracChangeset for help on using the changeset viewer.