Skip to content
This repository was archived by the owner on Mar 10, 2024. It is now read-only.

Commit f9e3343

Browse files
author
bhasher
committed
Editor Bugfix out of line and first char deletion
1 parent 307dfe8 commit f9e3343

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/publics/js/dev/page/editor/editable.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,18 @@ export default class Editable{
137137

138138
const line = getNodeFromAttribute('uuid');
139139

140-
if(!line) return;
140+
if(!line){
141+
e.preventDefault();
142+
temporaryCardAlert('Editor', 'Sorry, your action has been canceled because you are not on any line.', 5000);
143+
return;
144+
}
141145

142146
if(!anchorParent.hasAttribute('uuid')
143147
|| !focusParent.hasAttribute('uuid')
144148
|| ((Caret.getBeginPosition(line) === 0
145149
|| Caret.getEndPosition(line) === 0)
146150
) && anchorParent !== focusParent){
147-
e.preventDefault();
148-
temporaryCardAlert('Override', 'Sorry, you can\'t override the first char of a line', 5000);
149-
return;
151+
Caret.setRangeStart(line, 1);
150152
}
151153

152154
switch (e.keyCode) {
@@ -155,6 +157,11 @@ export default class Editable{
155157
this.insertTab();
156158
break;
157159
case 13: // enter
160+
if(e.shiftKey){
161+
temporaryCardAlert('Shift+Enter', 'Please just use Enter to avoid any bugs.', 5000);
162+
e.preventDefault();
163+
return;
164+
}
158165
if(this.keepSpace){
159166
Debug.debug('Prevent action when trying to add new line (key is probably maintain).');
160167
e.preventDefault();

src/publics/js/dev/utils/caret.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ export default class Caret{
6767
}
6868
}
6969

70+
71+
/**
72+
* Set the start range of the user caret on specified position in element or children
73+
* @param {HTMLElement|Node} element
74+
* @param {number} position
75+
*/
76+
static setRangeStart(element, position) {
77+
if (position >= 0) {
78+
let selection = document.getSelection();
79+
80+
let range = Caret.createRange(element, {count: position});
81+
selection.getRangeAt(0).setStart(range.endContainer, range.endOffset);
82+
83+
}
84+
}
85+
7086
/**
7187
* Get the position of the end of the user selection
7288
* Based on https://stackoverflow.com/a/4812022/11247647

0 commit comments

Comments
 (0)