From fdebb1061b3f1f5ee6cab299e5b72c45dcf2e076 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 27 Jan 2009 11:53:50 -0800 Subject: [PATCH] New keyboard shortcuts for switching to next open note and previous open note: Page down and page up. Also fixed visual bug that caused switching notes to flash when focusing. The fix involved calling Editor.reposition() at the top of resize() instead of at the end. --- NEWS | 2 ++ static/js/Editor.js | 7 ++++++- static/js/Wiki.js | 26 ++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 9c0cb7c..5826e01 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,7 @@ 1.6.0: January ??, 2009 * Switching between notebooks and loading notebooks is now much faster. + * New keyboard shortcuts for switching to next open note and previous open + note: Page down and page up. * Fixed various bugs related to the subscription page. 1.5.12: December 30, 2008 diff --git a/static/js/Editor.js b/static/js/Editor.js index 0cc4055..206fb3f 100644 --- a/static/js/Editor.js +++ b/static/js/Editor.js @@ -100,6 +100,7 @@ Editor.prototype.create_div = function ( position_after ) { this.holder = getElement( "note_holder_" + this.id ); this.connect_note_controls( true ); this.div = static_note_div; + this.div.editor = this; static_contents = getFirstElementByTagAndClassName( "span", "static_note_contents", this.div ); if ( static_contents && static_contents.innerHTML != this.initial_text ) static_contents.innerHTML = this.initial_text; @@ -615,6 +616,9 @@ Editor.prototype.query_command_value = function ( command ) { // resize the editor's frame to fit the dimensions of its content Editor.prototype.resize = function ( get_height_from_div ) { if ( !this.document ) return; + + this.reposition(); + var height = null; var width = elementDimensions( this.div.parentNode ).w; @@ -642,10 +646,11 @@ Editor.prototype.resize = function ( get_height_from_div ) { setElementDimensions( this.div, size ); var self = this; - this.reposition(); } Editor.prototype.reposition = function ( repeat ) { + if ( !this.iframe ) return; + // give the iframe the exact same position as the div it replaces. subtract the position of the // center_content_area container, which is relatively positioned var position = getElementPosition( this.div ); diff --git a/static/js/Wiki.js b/static/js/Wiki.js index fca24cd..2ccf617 100644 --- a/static/js/Wiki.js +++ b/static/js/Wiki.js @@ -1140,6 +1140,32 @@ Wiki.prototype.editor_key_pressed = function ( editor, event ) { editor.exec_command( "indent" ); event.stop(); + // page up: previous note + } else if ( code == 33 ) { + event.stop(); + + if ( !this.focused_editor ) return; + var previous_holder = this.focused_editor.holder.previousSibling; + if ( !previous_holder ) return; + if ( !hasElementClass( previous_holder, "note_holder" ) ) + previous_holder = previous_holder.previousSibling; + if ( !previous_holder || !hasElementClass( previous_holder, "note_holder" ) ) return; + var div = getFirstElementByTagAndClassName( "div", "static_note_div", previous_holder ); + if ( !div || !div.editor ) return; + div.editor.highlight(); + // page down: next note + } else if ( code == 34 ) { + event.stop(); + + if ( !this.focused_editor ) return; + var next_holder = this.focused_editor.holder.nextSibling; + if ( !next_holder ) return; + if ( !hasElementClass( next_holder, "note_holder" ) ) + next_holder = next_holder.nextSibling; + if ( !next_holder || !hasElementClass( next_holder, "note_holder" ) ) return; + var div = getFirstElementByTagAndClassName( "div", "static_note_div", next_holder ); + if ( !div || !div.editor ) return; + div.editor.highlight(); // IE: hitting space while making a link shouldn't end the link } else if ( code == 32 && editor.document.selection && editor.state_enabled( "a" ) ) { var range = editor.document.selection.createRange();