fnp
/
fnpeditor.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
5766035
)
editor: canvas - do not break an empty paragraph on ENTER
author
Aleksander Łukasz
<aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 6 Aug 2014 08:58:21 +0000
(10:58 +0200)
committer
Aleksander Łukasz
<aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 14 Aug 2014 14:26:13 +0000
(16:26 +0200)
src/editor/modules/documentCanvas/canvas/documentElement.js
patch
|
blob
|
history
src/editor/modules/documentCanvas/canvas/keyboard.js
patch
|
blob
|
history
src/editor/plugins/core/core.test.js
patch
|
blob
|
history
diff --git
a/src/editor/modules/documentCanvas/canvas/documentElement.js
b/src/editor/modules/documentCanvas/canvas/documentElement.js
index
c0dd361
..
a1965cd
100644
(file)
--- a/
src/editor/modules/documentCanvas/canvas/documentElement.js
+++ b/
src/editor/modules/documentCanvas/canvas/documentElement.js
@@
-241,6
+241,9
@@
$.extend(DocumentNodeElement.prototype, {
// })
this.dom.css('display', what);
this._container().css('display', what);
// })
this.dom.css('display', what);
this._container().css('display', what);
+ },
+ children: function() {
+ return [];
}
});
}
});
diff --git
a/src/editor/modules/documentCanvas/canvas/keyboard.js
b/src/editor/modules/documentCanvas/canvas/keyboard.js
index
7ae6b27
..
d8052ed
100644
(file)
--- a/
src/editor/modules/documentCanvas/canvas/keyboard.js
+++ b/
src/editor/modules/documentCanvas/canvas/keyboard.js
@@
-376,9
+376,16
@@
var keyEventHandlers = [
return s.type === 'caret' && e.key === KEYS.ENTER && !s.element.parent().isRootElement();
},
run: function(e, s) {
return s.type === 'caret' && e.key === KEYS.ENTER && !s.element.parent().isRootElement();
},
run: function(e, s) {
- var result, goto, gotoOptions;
+ var parent = s.element.parent(),
+ children = parent.children(),
+ result, goto, gotoOptions;
void(e);
e.preventDefault();
void(e);
e.preventDefault();
+
+ if(children.length === 1 && s.element.isEmpty()) {
+ return;
+ }
+
s.canvas.wlxmlDocument.transaction(function() {
result = s.element.wlxmlNode.breakContent({offset: s.offset});
}, {
s.canvas.wlxmlDocument.transaction(function() {
result = s.element.wlxmlNode.breakContent({offset: s.offset});
}, {
diff --git
a/src/editor/plugins/core/core.test.js
b/src/editor/plugins/core/core.test.js
index
f227b67
..
a33ae61
100644
(file)
--- a/
src/editor/plugins/core/core.test.js
+++ b/
src/editor/plugins/core/core.test.js
@@
-621,6
+621,17
@@
describe('Keyboard interactions', function() {
expect(selection.offset).to.equal(0);
});
expect(selection.offset).to.equal(0);
});
+ it('does nothing on an empty paragraph', function() {
+ var c = getCanvasFromXML('<section><div class="p">a</div></section>'),
+ k = new Keyboard(c),
+ spy = sinon.spy();
+
+ k.withCaret('a|').press(K.BACKSPACE);
+ c.wlxmlDocument.on('change', spy);
+ k.press(K.ENTER);
+ expect(spy.callCount).to.equal(0);
+ });
+
it('splits its parent box if inside a span', function() {
var c = getCanvasFromXML('<section><div class="p">this <span>is</span> a paragraph</div></section>'),
k = new Keyboard(c);
it('splits its parent box if inside a span', function() {
var c = getCanvasFromXML('<section><div class="p">this <span>is</span> a paragraph</div></section>'),
k = new Keyboard(c);