Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

better enter/entf/backspace handling

  • Loading branch information...
commit 9dd2f3082eac46a1c395dd4fcc6c827d301fda72 1 parent 69c361b
@johnny authored
Showing with 71 additions and 34 deletions.
  1. +4 −2 TODO
  2. +67 −32 source/javascripts/modes/wysiwygMode.js
View
6 TODO
@@ -1,13 +1,14 @@
* [30/40] Further improvements
- [-] wysiwyg
- [ ] expand selection to word boundaries, just as in textile
- - [ ] join lists on backspace/entf between lists
- [ ] Firefox: fix checkState for one bold word
- [ ] br tags should be top level, because Border expects that
or alternatively change behavior of the node search within Border
This would be the approach with a future since there might be other
cases of nested nodes ( b>i, i>b would be different now, but should
be the same)
+ - [X] pressing enter on empty list item should remove the list item and add a paragraph
+ - [X] join lists on backspace/entf between lists
- [X] Toolbar should work only if there is a range inside the preview
(also the state checking)
- [X] handle delete key
@@ -39,7 +40,6 @@
- [X] values for the selects should be defined by a method call if functions are defined
- [X] fields should share the combobox
- [ ] localization
- - [ ] flexible toolbar, which stays on top
- [ ] split up markupEditor.js
- [ ] look how ender handles the extensability
perhaps (... ME.Mode = Mode;})(ME, jQuery) is an option
@@ -48,9 +48,11 @@
- [ ] better editor loading
- [ ] handle multiple init gracefully. Currently it stacks two editors on top of each other
- [ ] loading from textarea with an unknown mode, that is inside a textarea, should work
+ - [ ] flexible toolbar, which stays on top
- [ ] spec with selenium
- [ ] spec press enter
- [ ] in list
+ - [ ] pressing enter on empty list item should remove the list item and add a paragraph
- [ ] in heading
- [ ] spec press shift enter
- [ ] in list
View
99 source/javascripts/modes/wysiwygMode.js
@@ -252,30 +252,49 @@
if(checkIfDeletedAll(preview,13) === false){
return false;
}
- var lastSibling = true, node, range, endContainer,
- block = editor.currentNodes.block;
-
- if(/h[1-5]/i.test(block.nodeName)){ // only headings
- range = selection.getRangeAt(0);
- node = endContainer = range.endContainer;
-
- // only the last sibling
- while(node.parentNode !== preview[0]){
- if(node.nextSibling){
- lastSibling = false;
- break;
- }
- node = node.parentNode;
+ var node, range, endContainer, insertNewParagraph, listItem,
+ lastSibling = true,
+ block = editor.currentNodes.block,
+ list = editor.currentNodes.list,
+ isHeading = /h[1-5]/i.test((list || block).nodeName);
+
+ if(!(isHeading || list)){
+ return;
+ }
+
+ range = selection.getRangeAt(0);
+ node = endContainer = range.endContainer;
+
+ // only the last sibling
+ while(node.parentNode !== preview[0]){
+ if(/li/i.test(node.nodeName)){
+ listItem = node;
}
-
- if(lastSibling
- && range.endOffset === endContainer.textContent.length // at
- // the end
- ){
- node = $("<p>").insertAfter(block);
- selectNodes(node);
+ if(node.nextSibling){
+ lastSibling = false;
+ break;
+ }
+ node = node.parentNode;
+ }
+
+ if(!lastSibling){
+ if(listItem && !$(listItem).text()){
+ disableList(editor);
return false;
}
+ } else if(isHeading && /* only headings */
+ // check if the cursor is at the end
+ range.endOffset === endContainer.textContent.length){
+ insertNewParagraph = true;
+ }
+ else if (list && !$(listItem).text()){
+ $(listItem).remove();
+ insertNewParagraph = true;
+ }
+ if(insertNewParagraph){
+ node = $("<p>").insertAfter(list || block);
+ selectNodes(node);
+ return false;
}
}
@@ -293,11 +312,12 @@
if(checkIfDeletedAll(preview,8) === false){
return false;
}
- var children, atBeginningOfLI,
+ var children, atBeginningOfLI, prevIsList, nextIsList,
inFirstSibling = true,
block = editor.currentNodes.block,
list = editor.currentNodes.list,
prev = (list || block).previousSibling,
+ next = (list || block).nextSibling,
range = selection.getRangeAt(0),
node = range.startContainer;
@@ -319,20 +339,30 @@
node = node.parentNode;
}
+ prevIsList = /(u|o)l/i.test(prev.nodeName);
+ nextIsList = /(u|o)l/i.test(next.nodeName);
+
if(inFirstSibling){
if(list){
node = node.firstChild;
}
+ if(prevIsList){
+ // append content to the last list item
+ prev = prev.lastChild;
+ }
node = $(node);
children = node.contents();
$(prev).append(children);
node.remove();
selectNodes([children[0]], true);
+ if(prevIsList && nextIsList){
+ $(prev).parent().append($(next).detach().contents());
+ }
} else if(list && atBeginningOfLI){
disableList(editor);
}
-
+
return false;
}
@@ -349,7 +379,7 @@
if(!$.browser.webkit){
return true;
}
- var children,
+ var children, nextIsList,
block = editor.currentNodes.block,
list = editor.currentNodes.list,
next = (list || block).nextSibling,
@@ -360,7 +390,7 @@
return true;
}
- // only the first sibling
+ // only the last sibling
while(node.parentNode !== preview[0]){
if(node.nextSibling){
return true;
@@ -368,14 +398,19 @@
node = node.parentNode;
}
- if(list){
- // append to last list item
- node = node.lastChild;
- }
- if(/(u|o)l/i.test(next.nodeName)){
- // swallow only the first list item
- next = next.firstChild;
+ nextIsList = /(u|o)l/i.test(next.nodeName);
+
+ if(!(nextIsList && list)){
+ if(list){
+ // append to last list item
+ node = node.lastChild;
+ }
+ if(nextIsList){
+ // swallow only the first list item
+ next = next.firstChild;
+ }
}
+
next = $(next);
children = next.contents();
Please sign in to comment.
Something went wrong with that request. Please try again.