X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/3b9b115efb44c7570453c0729f05f83a3b45cd4d..46fdcc29313a6c0dd897b8060335061f433897fd:/project/static/js/views/xml.js?ds=inline diff --git a/project/static/js/views/xml.js b/project/static/js/views/xml.js index d24dfa94..1681caee 100644 --- a/project/static/js/views/xml.js +++ b/project/static/js/views/xml.js @@ -1,4 +1,4 @@ -/*global View CodeMirror ButtonToolbarView render_template panels */ +/*global View CodeMirror ToolbarView render_template panels */ var XMLView = View.extend({ _className: 'XMLView', element: null, @@ -18,8 +18,11 @@ var XMLView = View.extend({ var self = this; $('.xmlview-toolbar', this.element).bind('resize.xmlview', this.resized.bind(this)); - - + + // scroll to the given position (if availble) + this.scrollCallback = this.scrollOnRequest.bind(this); + $(document).bind('xml-scroll-request', this.scrollCallback); + this.parent.freeze('Ładowanie edytora...'); this.editor = new CodeMirror($('.xmlview', this.element).get(0), { parserfile: 'parsexml.js', @@ -28,7 +31,7 @@ var XMLView = View.extend({ parserConfig: { useHTMLKludges: false }, - textWrapping: false, + textWrapping: true, tabMode: 'spaces', indentUnit: 0, onChange: this.editorDataChanged.bind(this), @@ -91,6 +94,8 @@ var XMLView = View.extend({ }, dispose: function() { + $(document).unbind('xml-scroll-request', this.scrollCallback); + this.model.removeObserver(this); $(this.editor.frame).remove(); this._super(); @@ -98,20 +103,23 @@ var XMLView = View.extend({ getHotkey: function(event) { var code = event.keyCode; + if(!((code >= 97 && code <= 122) + || (code >= 65 && code <= 90)) ) return null; + var ch = String.fromCharCode(code & 0xff).toLowerCase(); - var button = $('.buttontoolbarview-button[title='+ch+']', this.element)[0] + /* # console.log(ch.charCodeAt(0), '#', buttons); */ - console.log(ch, '#', button); + var buttons = $('.buttontoolbarview-button[hotkey='+ch+']', this.element); var mod = 0; if(event.altKey) mod |= 0x01; if(event.ctrlKey) mod |= 0x02; if(event.shiftKey) mod |= 0x04; - if(button) { + if(buttons.length) { var match = null; - $(button).each(function() { + buttons.each(function() { if( parseInt($(this).attr('ui:hotkey_mod')) == mod ) { match = this; return; @@ -126,8 +134,7 @@ var XMLView = View.extend({ }, isHotkey: function() { - console.log(arguments); - + /* console.log(arguments); */ if(this.getHotkey.apply(this, arguments)) return true; else @@ -139,6 +146,16 @@ var XMLView = View.extend({ this.buttonToolbar.buttonPressed({ target: button }); + }, + + scrollOnRequest: function(event, data) + { + try { + var line = this.editor.nthLine(data.line); + this.editor.selectLines(line, (data.column-1)); + } catch(e) { + console.log('Exception in scrollOnRequest:', e); + } } });