-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Caret module: initial #242
Conversation
*/ | ||
constructor() { | ||
|
||
this.instance = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зачем это, если все методы статичны?
src/components/utils.js
Outdated
* Returns basic nodetypes as contants | ||
* @return {{TAG: number, TEXT: number, COMMENT: number, DOCUMENT_FRAGMENT: number}} | ||
*/ | ||
static get nodeTypes() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Для этого вроде какая-то нативная штука появилась
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$1.nodeType === Node.ELEMENT_NODE
$1.nodeType === Node.TEXT_NODE
etc
src/components/dom.js
Outdated
* @param {Node} node | ||
* @return {*|boolean} | ||
*/ | ||
static isLeaf(node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need more evident name
src/components/dom.js
Outdated
/** | ||
* checks node if it is doesn't have child node | ||
* @param {Node} node | ||
* @return {*|boolean} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why return type is any
? Seems like it always returns boolean
src/components/dom.js
Outdated
} | ||
|
||
/** | ||
* checks node if it is doesn't have child node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... any child nodes?
src/components/dom.js
Outdated
@@ -35,6 +35,18 @@ export default class Dom { | |||
|
|||
} | |||
|
|||
/** | |||
* Creates text Node with content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creates Text Node with the passed content
src/components/dom.js
Outdated
@@ -86,6 +98,55 @@ export default class Dom { | |||
|
|||
} | |||
|
|||
/** | |||
* Search for deepest node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does it means deepest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node
src/components/dom.js
Outdated
* | ||
* @return {Boolean} true if it is empty | ||
*/ | ||
static checkNodeEmpty(node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isEmptyNode
src/components/dom.js
Outdated
|
||
nodeText = node.value; | ||
|
||
if ( nodeText.trim() ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move this block under the
if ( this.isElement(node) && this.isNativeInput(node) ) {
} else {
}
and remove similar one from the second part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And replace it with
return nodeText.trim().length === 0;
src/components/dom.js
Outdated
} | ||
|
||
/** | ||
* breadth-first search |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't looks like anyone can understand this.
src/components/dom.js
Outdated
|
||
if (!node) { | ||
|
||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined
is not empty Node? Maybe you should throw an Error there? or add a console.assert
src/components/dom.js
Outdated
static isEmpty(node) { | ||
|
||
let treeWalker = [], | ||
stack = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what stack it is?
src/components/utils.js
Outdated
* Returns basic nodetypes as contants | ||
* @return {{TAG: number, TEXT: number, COMMENT: number, DOCUMENT_FRAGMENT: number}} | ||
*/ | ||
static get nodeTypes() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$1.nodeType === Node.ELEMENT_NODE
$1.nodeType === Node.TEXT_NODE
etc
break; | ||
case _.keyCodes.DOWN: | ||
case _.keyCodes.RIGHT: | ||
this.blockRightOrDownArrowPressed(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goToNextBlock
break; | ||
case _.keyCodes.UP: | ||
case _.keyCodes.LEFT: | ||
this.blockLeftOrUpArrowPressed(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goToPrevoiusBlock
*/ | ||
blockRightOrDownArrowPressed() { | ||
|
||
let currentBlock = this.currentBlock, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant variable
lastTextNode = $.getDeepestTextNode(currentBlock.pluginsContent, true), | ||
textNodeLength = lastTextNode.length; | ||
|
||
if (Selection.getSelectionAnchorNode() !== lastTextNode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Selection.getAnchorNode
@@ -128,6 +239,62 @@ export default class BlockManager extends Module { | |||
|
|||
} | |||
|
|||
/** | |||
* | |||
* @return {*} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{Block}
@@ -128,6 +239,62 @@ export default class BlockManager extends Module { | |||
|
|||
} | |||
|
|||
/** | |||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description is missed
} | ||
|
||
/** | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Desc is missed
* Returns next Block instance | ||
* @return {*} | ||
*/ | ||
getNextBlock() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be implemented via getter nextBlock
/** | ||
* Returns previous Block instance | ||
*/ | ||
getPreviousBlock() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be implemented via getter previousBlock
@@ -0,0 +1 @@ | |||
# CodeX Editor Caret Module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove or fill this document
|
||
} | ||
|
||
if (Selection.getSelectionAnchorOffset() === textNodeLength) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant «Selection» word
let lastTextNode = $.getDeepestNode(this.currentBlock.pluginsContent, true), | ||
textNodeLength = lastTextNode.length; | ||
|
||
if (Selection.getSelectionAnchorNode() !== lastTextNode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant «Selection» word.
/** | ||
* @todo Refactor method when code above will be moved to the keydown module | ||
*/ | ||
navigatePrevious() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description is missed
/** | ||
* @todo Refactor method when code above will be moved to the keydown module | ||
*/ | ||
navigateNext() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description is missed
src/components/modules/ui.js
Outdated
@@ -224,6 +224,14 @@ export default class UI extends Module { | |||
|
|||
let clickedNode = event.target; | |||
|
|||
console.log('click', clickedNode); | |||
if ( clickedNode.classList.contains(this.CSS.editorZone) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't work with clicks on inner-elements. What behaviour do you expect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it is already working with setToTheLastBlock
. See below
src/components/modules/ui.js
Outdated
@@ -352,6 +360,26 @@ export default class UI extends Module { | |||
|
|||
} | |||
|
|||
clickedOnRedactorZone(event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs are missed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | ||
* Working with selection | ||
*/ | ||
export default class Selection { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad name, that conflicts with window.Selection
src/components/selection.js
Outdated
|
||
} | ||
|
||
static getSelection() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant Selection
-word all method's names.
src/components/selection.js
Outdated
|
||
} | ||
|
||
static getSelection() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs are missed
src/components/modules/caret.js
Outdated
*/ | ||
if ($.isEmpty(pluginsContent)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лучше оставить геттер isEmpty
у Block. Там проверяется не только пустота контента. Можешь принести туда свой $.isEmpty
вместо this._html.textContent.trim().length === 0
src/components/modules/caret.js
Outdated
|
||
} | ||
|
||
_.delay( () => this.set(nodeToSet, offset), 20)(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зачем тут это?
No description provided.