Intentionally *not* showing a link pulldown when you start a link and begin
typing. Only showing the pulldown when you end the link (or when you navigate away and then come back).
This commit is contained in:
parent
1f87db664b
commit
49a692f378
|
@ -9,6 +9,7 @@ function Editor( id, notebook_id, note_text, deleted_from, revisions_list, read_
|
||||||
this.init_highlight = highlight || false;
|
this.init_highlight = highlight || false;
|
||||||
this.init_focus = focus || false;
|
this.init_focus = focus || false;
|
||||||
this.closed = false;
|
this.closed = false;
|
||||||
|
this.link_started = null;
|
||||||
var iframe_id = "note_" + id;
|
var iframe_id = "note_" + id;
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
@ -244,15 +245,17 @@ Editor.prototype.key_pressed = function ( event ) {
|
||||||
Editor.prototype.key_released = function ( event ) {
|
Editor.prototype.key_released = function ( event ) {
|
||||||
this.resize();
|
this.resize();
|
||||||
|
|
||||||
// if non-alphabetic (a-z), non-ctrl keys are released, issue a state changed event
|
// if ctrl keys are released, bail
|
||||||
var code = event.key().code;
|
var code = event.key().code;
|
||||||
if ( ( code >= 65 && code <= 90 ) || event.modifier().ctrl )
|
if ( event.modifier().ctrl )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
signal( this, "state_changed", this );
|
signal( this, "state_changed", this );
|
||||||
}
|
}
|
||||||
|
|
||||||
Editor.prototype.mouse_clicked = function ( event ) {
|
Editor.prototype.mouse_clicked = function ( event ) {
|
||||||
|
this.link_started = null;
|
||||||
|
|
||||||
// update the state no matter what, in case the cursor has moved
|
// update the state no matter what, in case the cursor has moved
|
||||||
if ( this.read_write )
|
if ( this.read_write )
|
||||||
signal( this, "state_changed", this );
|
signal( this, "state_changed", this );
|
||||||
|
@ -334,12 +337,14 @@ Editor.prototype.start_link = function () {
|
||||||
// hack to prevent Firefox from erasing spaces before links that happen to be at the end of list items
|
// hack to prevent Firefox from erasing spaces before links that happen to be at the end of list items
|
||||||
var sentinel = createDOM( "span" );
|
var sentinel = createDOM( "span" );
|
||||||
insertSiblingNodesBefore( placeholder.parentNode, sentinel );
|
insertSiblingNodesBefore( placeholder.parentNode, sentinel );
|
||||||
|
this.link_started = placeholder.parentNode;
|
||||||
|
|
||||||
// nuke the link title and collapse the selection, yielding a tasty new link that's completely
|
// nuke the link title and collapse the selection, yielding a tasty new link that's completely
|
||||||
// titleless and unselected
|
// titleless and unselected
|
||||||
removeElement( placeholder );
|
removeElement( placeholder );
|
||||||
// otherwise, just create a link with the selected text as the link title
|
// otherwise, just create a link with the selected text as the link title
|
||||||
} else {
|
} else {
|
||||||
|
this.link_started = null;
|
||||||
this.exec_command( "createLink", "/notebooks/" + this.notebook_id + "?note_id=new" );
|
this.exec_command( "createLink", "/notebooks/" + this.notebook_id + "?note_id=new" );
|
||||||
var link = this.find_link_at_cursor();
|
var link = this.find_link_at_cursor();
|
||||||
signal( this, "resolve_link", link_title( link ), link );
|
signal( this, "resolve_link", link_title( link ), link );
|
||||||
|
@ -354,7 +359,9 @@ Editor.prototype.start_link = function () {
|
||||||
range.moveStart( "character", -1 );
|
range.moveStart( "character", -1 );
|
||||||
range.select();
|
range.select();
|
||||||
this.exec_command( "createLink", "/notebooks/" + this.notebook_id + "?note_id=new" );
|
this.exec_command( "createLink", "/notebooks/" + this.notebook_id + "?note_id=new" );
|
||||||
|
this.link_started = this.find_link_at_cursor();
|
||||||
} else {
|
} else {
|
||||||
|
this.link_started = null;
|
||||||
this.exec_command( "createLink", "/notebooks/" + this.notebook_id + "?note_id=new" );
|
this.exec_command( "createLink", "/notebooks/" + this.notebook_id + "?note_id=new" );
|
||||||
var link = this.find_link_at_cursor();
|
var link = this.find_link_at_cursor();
|
||||||
signal( this, "resolve_link", link_title( link ), link );
|
signal( this, "resolve_link", link_title( link ), link );
|
||||||
|
@ -363,6 +370,7 @@ Editor.prototype.start_link = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
Editor.prototype.end_link = function () {
|
Editor.prototype.end_link = function () {
|
||||||
|
this.link_started = null;
|
||||||
var link = this.find_link_at_cursor();
|
var link = this.find_link_at_cursor();
|
||||||
|
|
||||||
if ( this.iframe.contentWindow && this.iframe.contentWindow.getSelection ) { // browsers such as Firefox
|
if ( this.iframe.contentWindow && this.iframe.contentWindow.getSelection ) { // browsers such as Firefox
|
||||||
|
@ -400,6 +408,8 @@ Editor.prototype.find_link_at_cursor = function () {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( link != this.link_started )
|
||||||
|
this.link_started = null;
|
||||||
if ( link ) return link;
|
if ( link ) return link;
|
||||||
|
|
||||||
// well, that didn't work, so try the selection's focus node instead
|
// well, that didn't work, so try the selection's focus node instead
|
||||||
|
@ -407,10 +417,14 @@ Editor.prototype.find_link_at_cursor = function () {
|
||||||
|
|
||||||
while ( link.nodeName != "A" ) {
|
while ( link.nodeName != "A" ) {
|
||||||
link = link.parentNode;
|
link = link.parentNode;
|
||||||
if ( !link )
|
if ( !link ) {
|
||||||
|
this.link_started = null;
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( link != this.link_started )
|
||||||
|
this.link_started = null;
|
||||||
return link;
|
return link;
|
||||||
} else if ( this.document.selection ) { // browsers such as IE
|
} else if ( this.document.selection ) { // browsers such as IE
|
||||||
var range = this.document.selection.createRange();
|
var range = this.document.selection.createRange();
|
||||||
|
@ -418,13 +432,18 @@ Editor.prototype.find_link_at_cursor = function () {
|
||||||
|
|
||||||
while ( link.nodeName != "A" ) {
|
while ( link.nodeName != "A" ) {
|
||||||
link = link.parentNode;
|
link = link.parentNode;
|
||||||
if ( !link )
|
if ( !link ) {
|
||||||
|
this.link_started = null;
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( link != this.link_started )
|
||||||
|
this.link_started = null;
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.link_started = null;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -500,7 +500,9 @@ Wiki.prototype.display_link_pulldown = function ( editor, link ) {
|
||||||
if ( !link )
|
if ( !link )
|
||||||
link = editor.find_link_at_cursor();
|
link = editor.find_link_at_cursor();
|
||||||
|
|
||||||
if ( !link ) {
|
// if there's no link at the current cursor location, or there is a link but it was just started,
|
||||||
|
// bail
|
||||||
|
if ( !link || link == editor.link_started ) {
|
||||||
this.clear_pulldowns();
|
this.clear_pulldowns();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue