Skip to content
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

Merged
merged 14 commits into from
Jan 4, 2018
Merged

Caret module: initial #242

merged 14 commits into from
Jan 4, 2018

Conversation

khaydarov
Copy link
Member

No description provided.

*/
constructor() {

this.instance = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем это, если все методы статичны?

* Returns basic nodetypes as contants
* @return {{TAG: number, TEXT: number, COMMENT: number, DOCUMENT_FRAGMENT: number}}
*/
static get nodeTypes() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для этого вроде какая-то нативная штука появилась

Copy link
Member

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

* @param {Node} node
* @return {*|boolean}
*/
static isLeaf(node) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need more evident name

/**
* checks node if it is doesn't have child node
* @param {Node} node
* @return {*|boolean}
Copy link
Member

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

}

/**
* checks node if it is doesn't have child node
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... any child nodes?

@@ -35,6 +35,18 @@ export default class Dom {

}

/**
* Creates text Node with content
Copy link
Member

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

@@ -86,6 +98,55 @@ export default class Dom {

}

/**
* Search for deepest node
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node

*
* @return {Boolean} true if it is empty
*/
static checkNodeEmpty(node) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isEmptyNode


nodeText = node.value;

if ( nodeText.trim() ) {
Copy link
Member

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

Copy link
Member

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;

}

/**
* breadth-first search
Copy link
Member

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.


if (!node) {

return false;
Copy link
Member

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

static isEmpty(node) {

let treeWalker = [],
stack = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what stack it is?

* Returns basic nodetypes as contants
* @return {{TAG: number, TEXT: number, COMMENT: number, DOCUMENT_FRAGMENT: number}}
*/
static get nodeTypes() {
Copy link
Member

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();
Copy link
Member

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();
Copy link
Member

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,
Copy link
Member

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) {
Copy link
Member

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 {*}
Copy link
Member

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 {

}

/**
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description is missed

}

/**
*
Copy link
Member

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() {
Copy link
Member

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() {
Copy link
Member

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
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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() {
Copy link
Member

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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description is missed

@@ -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) ) {
Copy link
Member

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?

Copy link
Member

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

@@ -352,6 +360,26 @@ export default class UI extends Module {

}

clickedOnRedactorZone(event) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs are missed

Copy link
Member

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 {
Copy link
Member

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


}

static getSelection() {
Copy link
Member

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.


}

static getSelection() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs are missed

*/
if ($.isEmpty(pluginsContent)) {
Copy link
Member

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


}

_.delay( () => this.set(nodeToSet, offset), 20)();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем тут это?

@khaydarov khaydarov merged commit 6fd28f3 into rewriting-version2.0 Jan 4, 2018
@khaydarov khaydarov deleted the module-caret branch January 4, 2018 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants