Skip to content

Commit

Permalink
Fixes for selection replacement when adding links.
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
  • Loading branch information
ncb000gt committed Mar 4, 2011
1 parent 065215a commit d80263a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
*.swp
*.swo
10 changes: 6 additions & 4 deletions src/Ext.ux.form.HtmlEditor.Link.js
Expand Up @@ -73,6 +73,7 @@ Ext.ux.form.HtmlEditor.Link = Ext.extend(Ext.util.Observable, {
buttons: [{
text: this.langInsert,
handler: function(){
//TODO: not having new idx's for the component could cause issues around multiple edit areas
var frm = this.linkWindow.getComponent('insert-link').getForm();
if (frm.isValid()) {
var afterSpace = '', sel = this.cmp.getSelectedText(true), text = frm.findField('text').getValue(), url = frm.findField('url').getValue(), target = frm.findField('target').getValue();
Expand All @@ -83,23 +84,24 @@ Ext.ux.form.HtmlEditor.Link = Ext.extend(Ext.util.Observable, {
if (sel.hasHTML) {
text = sel.html;
}
var html = '<a href="' + url + '" target="' + target + '">' + text + '</a>' + afterSpace;
var html = '<a href="' + url + '" target="' + target + '">' + text + '</a> ' + afterSpace;
this.cmp.insertAtCursor(html);
this.linkWindow.hide();
this.linkWindow.close();
this.linkWindow = null;
} else {
if (!frm.findField('url').isValid()) {
frm.findField('url').getEl().frame();
} else if (!frm.findField('target').isValid()) {
frm.findField('target').getEl().frame();
}
}

},
scope: this
}, {
text: this.langCancel,
handler: function(){
this.linkWindow.close();
this.linkWindow = null;
},
scope: this
}],
Expand All @@ -108,7 +110,7 @@ Ext.ux.form.HtmlEditor.Link = Ext.extend(Ext.util.Observable, {
fn: function(){
var frm = this.linkWindow.getComponent('insert-link').getForm();
frm.findField('text').setValue(sel.textContent).setDisabled(sel.hasHTML);
frm.findField('url').reset().focus(true, 50);
frm.findField('url').focus(true, 50);
},
scope: this,
defer: 350
Expand Down
5 changes: 5 additions & 0 deletions src/Ext.ux.form.HtmlEditor.MidasCommand.js
Expand Up @@ -29,6 +29,7 @@ Ext.override(Ext.form.HtmlEditor, {
} else {
selDocFrag = this.win.getSelection().getRangeAt(0).cloneContents();
}

Ext.each(selDocFrag.childNodes, function(n){
if (n.nodeType !== 3) {
hasHTML = true;
Expand All @@ -42,6 +43,10 @@ Ext.override(Ext.form.HtmlEditor, {
} else {
html = txt = selDocFrag.textContent;
}
if (clip) {
//selection range sticks around unless you collapse it.
sel.collapseToStart();
}
ret = {
textContent: txt,
hasHTML: hasHTML,
Expand Down

0 comments on commit d80263a

Please sign in to comment.