Fix jumping caret bug (#568)

* Fix jumping caret bug

* Get element from point
This commit is contained in:
George Berezhnoy 2018-12-24 21:40:15 +03:00 committed by GitHub
parent cfae683d6a
commit 5b156c1875
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 64 additions and 52 deletions

12
dist/codex-editor.js vendored

File diff suppressed because one or more lines are too long

View file

@ -76,6 +76,32 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
regenerator-runtime regenerator-runtime
MIT MIT
@babel/register
MIT
MIT License
Copyright (c) 2014-2018 Sebastian McKenzie <sebmck@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
codex-notifier codex-notifier
MIT MIT
MIT License MIT License
@ -376,29 +402,3 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@babel/register
MIT
MIT License
Copyright (c) 2014-2018 Sebastian McKenzie <sebmck@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -1,6 +1,6 @@
{ {
"name": "codex.editor", "name": "codex.editor",
"version": "2.7.16", "version": "2.7.17",
"description": "CodeX Editor. Native JS, based on API and Open Source", "description": "CodeX Editor. Native JS, based on API and Open Source",
"main": "dist/codex-editor.js", "main": "dist/codex-editor.js",
"types": "./types/index.d.ts", "types": "./types/index.d.ts",

View file

@ -137,7 +137,7 @@ export default class InlineToolbar extends Module {
* @param {KeyboardEvent|MouseEvent} event * @param {KeyboardEvent|MouseEvent} event
*/ */
public handleShowingEvent(event): void { public handleShowingEvent(event): void {
if (!this.allowedToShow(event)) { if (!this.allowedToShow()) {
this.close(); this.close();
return; return;
} }
@ -183,7 +183,7 @@ export default class InlineToolbar extends Module {
*/ */
public close(): void { public close(): void {
this.nodes.wrapper.classList.remove(this.CSS.inlineToolbarShowed); this.nodes.wrapper.classList.remove(this.CSS.inlineToolbarShowed);
this.tools.forEach((toolInstance, toolName) => { this.tools.forEach((toolInstance) => {
if (typeof toolInstance.clear === 'function') { if (typeof toolInstance.clear === 'function') {
toolInstance.clear(); toolInstance.clear();
} }
@ -216,27 +216,15 @@ export default class InlineToolbar extends Module {
/** /**
* Need to show Inline Toolbar or not * Need to show Inline Toolbar or not
* @param {KeyboardEvent|MouseEvent} event
*/ */
private allowedToShow(event): boolean { private allowedToShow(): boolean {
/** /**
* Tags conflicts with window.selection function. * Tags conflicts with window.selection function.
* Ex. IMG tag returns null (Firefox) or Redactors wrapper (Chrome) * Ex. IMG tag returns null (Firefox) or Redactors wrapper (Chrome)
*/ */
const tagsConflictsWithSelection = ['IMG', 'INPUT']; const tagsConflictsWithSelection = ['IMG', 'INPUT'];
const currentSelection = SelectionUtils.get();
if (event && tagsConflictsWithSelection.includes(event.target.tagName)) { const selectedText = SelectionUtils.text;
return false;
}
// The selection of the element only in contenteditable
const contenteditable = event.target.closest('[contenteditable="true"]');
if (contenteditable === null) {
return false;
}
const currentSelection = SelectionUtils.get(),
selectedText = SelectionUtils.text;
// old browsers // old browsers
if (!currentSelection || !currentSelection.anchorNode) { if (!currentSelection || !currentSelection.anchorNode) {
@ -248,6 +236,18 @@ export default class InlineToolbar extends Module {
return false; return false;
} }
const target = currentSelection.anchorNode.parentElement;
if (currentSelection && tagsConflictsWithSelection.includes(target.tagName)) {
return false;
}
// The selection of the element only in contenteditable
const contenteditable = target.closest('[contenteditable="true"]');
if (contenteditable === null) {
return false;
}
// is enabled by current Block's Tool // is enabled by current Block's Tool
const currentBlock = this.Editor.BlockManager.getBlock(currentSelection.anchorNode as HTMLElement); const currentBlock = this.Editor.BlockManager.getBlock(currentSelection.anchorNode as HTMLElement);
@ -367,7 +367,7 @@ export default class InlineToolbar extends Module {
return (toolClass as ToolSettings).class[Tools.apiSettings.IS_INLINE]; return (toolClass as ToolSettings).class[Tools.apiSettings.IS_INLINE];
}) })
.map(([name, toolClass]: [string, InlineToolConstructable | ToolSettings]) => name); .map(([name]: [string, InlineToolConstructable | ToolSettings]) => name);
/** /**
* 1) For internal tools, check public getter 'shortcut' * 1) For internal tools, check public getter 'shortcut'

View file

@ -290,7 +290,19 @@ export default class UI extends Module {
* *
*/ */
private redactorClicked(event: MouseEvent): void { private redactorClicked(event: MouseEvent): void {
const clickedNode = event.target as HTMLElement;
if (!Selection.isCollapsed) {
return;
}
let clickedNode = event.target as HTMLElement;
/**
* If click was fired is on Editor`s wrapper, try to get clicked node by elementFromPoint method
*/
if (clickedNode === this.nodes.redactor) {
clickedNode = document.elementFromPoint(event.clientX, event.clientY) as HTMLElement;
}
/** /**
* Select clicked Block as Current * Select clicked Block as Current