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

Split blocks #246

Merged
merged 21 commits into from
Jan 11, 2018
Merged

Split blocks #246

merged 21 commits into from
Jan 11, 2018

Conversation

Nikitos9I
Copy link

@Nikitos9I Nikitos9I commented Jan 8, 2018

closes #229
closes #247


super({config});

document.body.addEventListener('keydown', this.keyBoardListener.bind(this));
Copy link
Member

Choose a reason for hiding this comment

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

можно коллбэк передать так: (event) => { this.keyBoardListener(event) });


switch(event.keyCode) {

case (8):
Copy link
Member

Choose a reason for hiding this comment

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

в utils у нас есть константы:
_.keyCodes.ENTER, _.keyCodes.BACKSPACE ....


case (13):
console.log('enter pressed');

Copy link
Member

Choose a reason for hiding this comment

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

много пустых строк


event.preventDefault();

this.Editor.BlockManager.insert('text', this.getDataFromRange());
Copy link
Member

Choose a reason for hiding this comment

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

Мне кажется лучше добавить еще одну функцию, например, enterPressed()
а в ней уже делать insert. Просто возможно при нажатии на ентер будут происходить еще другие события.

}

/**
* Gets data from blocks
Copy link
Member

@khaydarov khaydarov Jan 8, 2018

Choose a reason for hiding this comment

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

Функцию стоит нормально задокументировать. Описать что происходит и как

*/
getDataFromRange() {

let selection = window.getSelection();
Copy link
Member

Choose a reason for hiding this comment

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

Для работы с селекшном у нас есть класс, добавь его перед строчкой с exports
import Selection from '../Selection'

let selection = Selection.get()

getDataFromRange() {

let selection = window.getSelection();
let range = new Range();
Copy link
Member

Choose a reason for hiding this comment

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

можно через запятую объявить переменную, let selection= ..., range = new Range()

let selection = window.getSelection();
let range = new Range();

let cnt = this.Editor.BlockManager.currentBlock.pluginsContent,
Copy link
Member

Choose a reason for hiding this comment

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

название переменной не очень удачное. Можно javascript let pluginsContent = ....., lastNode = $.getDeepestNode(pluginsContent, true) -> описать почему true

selection.addRange(range);

let fragm = range.extractContents();
let div = document.createElement('div');
Copy link
Member

Choose a reason for hiding this comment

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

let extractedFragment = range.extractContenst(),
     wrapper = $.make('div', []. {});

wrapper.append(extractedFragment.cloneNode(true));

.....```


super({config});

document.body.addEventListener('keydown', this.keyBoardListener.bind(this));
Copy link
Member

Choose a reason for hiding this comment

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

document.body.addEventListener('keydown', event => this.keyBoardListener(event));

}

/**
* handler processes special keyboard keys
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 mean?


switch(event.keyCode) {

case (8):
Copy link
Member

Choose a reason for hiding this comment

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

use Utils#keyCodes instead of Magic numbers


event.preventDefault();

this.Editor.BlockManager.insert('text', this.getDataFromRange());
Copy link
Member

Choose a reason for hiding this comment

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

new block will be inserted and the end of the Editor or below current block?

Copy link
Author

@Nikitos9I Nikitos9I Jan 8, 2018

Choose a reason for hiding this comment

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

Ниже активного блока. Функция insert() сама это делает

/**
* Gets data from blocks
*/
getDataFromRange() {
Copy link
Member

Choose a reason for hiding this comment

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

This method should be in the BlockManager class. And better name it split

@khaydarov
Copy link
Member

khaydarov commented Jan 8, 2018

А вообще, мне кажется будет правильнее сделать так:
модуль Caret отвечает за работу с кареткой, следовательно, вынести выделение и extract в метод каретки, например,

extractDataFromCaretPosition (или как-то так) () {
       // сюда перенести только выделение и extractContents 
      return fragment; // вернуть только вырезанный фрагмент
}

// В блок-менеджере будет функция split

split() {
     let extractedFragment = this.Editor.Caret.extractFromCaretPosition();
    
     // создание data 
    this.insert('text', data);
}

В keyboards:

enterPressed() {
    
    this.Editor.BlockManager.split(); 

   // дальше делает что-то другое, например, переносим тулбар

}

selection.removeAllRanges();
selection.addRange(range);

let extractedFragment = range.extractContents(),
Copy link
Member

Choose a reason for hiding this comment

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

нужно в модуле Caret создать универсальную функцию, которая вырежет любой фрагмент из блока. Для начала можно просто создать extractFragmentFromCaretPosition() и вынести код до extractContents в эту функцию (extractFragmentFromCaretPosition)


super({config});

document.body.addEventListener('keydown', event => this.keyBoardListener(event));
Copy link
Member

Choose a reason for hiding this comment

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

javascript this.Editor.Listener.on(document.body, 'keydown', event => this.keyBoardListener(event));

case _.keyCodes.ENTER:

_.log('Enter key pressed');
event.preventDefault();
Copy link
Member

Choose a reason for hiding this comment

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

preventDefault лучше занести в enterPressed(). Не всегда нужно прерывать дефолтное поведение

case _.keyCodes.RIGHT:

_.log('Right key pressed');
this.Editor.BlockManager.navigateNext();
Copy link
Member

Choose a reason for hiding this comment

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

case _.keyCodes.DOWN:
case _.keyCodes.RIGHT:

    _.log('Right and DOWN key pressed');
    this.arrowRightAndDownPressed();
   break;
}
arrowRightAndDownPressed() {
   this.Editor.BlockManager.navigateNext();
}

то же самое с UP и LEFT

let block = this.composeBlock(toolName, data);

this._blocks[++this.currentBlockIndex] = block;
this.Editor.Caret.setToBlock(block);

}

/**
* Insert extract content form current block to below current block
Copy link
Member

Choose a reason for hiding this comment

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

insert extracted content from current block to block that is below

Copy link
Member

Choose a reason for hiding this comment

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

or next to the current

@@ -116,4 +116,25 @@ export default class Caret extends Module {

}

/**
* Extract fragment of content current block form caret position
Copy link
Member

Choose a reason for hiding this comment

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

Extract content fragment of current block from caret position

let selection = Selection.get(),
range = new Range();

let cnt = this.Editor.BlockManager.currentBlock.pluginsContent,
Copy link
Member

Choose a reason for hiding this comment

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

cnt -> pluginsContent

@@ -0,0 +1,98 @@
import Selection from '../Selection';
Copy link
Member

Choose a reason for hiding this comment

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

импорт тут значит не нужен, и это отлично

@Nikitos9I Nikitos9I changed the title Split merge blocks Split blocks Jan 8, 2018
let block = this.composeBlock(toolName, data);

this._blocks[++this.currentBlockIndex] = block;
this.Editor.Caret.setToBlock(block);

}

/**
* Insert extract content form current block to block that is below
Copy link
Member

Choose a reason for hiding this comment

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

extracted

и вроде можно убрать that is

Copy link
Member

Choose a reason for hiding this comment

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

И коммент немного не понятный.
Вставляем контент из текущего блока в следующий. Разве этим split занимается?

let extractedFragment = this.Editor.Caret.extractFragmentFromCaretPosition(),
wrapper = $.make('div');

wrapper.append(extractedFragment.cloneNode(true));
Copy link
Member

Choose a reason for hiding this comment

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

Поясни зачем клонирование


wrapper.append(extractedFragment.cloneNode(true));

let data = {
Copy link
Member

Choose a reason for hiding this comment

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

Оставь здесь @todo

range = new Range();

let pluginsContent = this.Editor.BlockManager.currentBlock.pluginsContent,
lastNode = $.getDeepestNode(pluginsContent, true);
Copy link
Member

Choose a reason for hiding this comment

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

Коммент, что означает true

}

/**
* Should be called after Editor.BlockManager preparation
Copy link
Member

Choose a reason for hiding this comment

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

А почем именно после менеджера?

}

/**
* Handler on Editor for keyboard keys
Copy link
Member

Choose a reason for hiding this comment

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

Не понятно что ловишь. keyup, keydown или еще что.

*/
prepare() {

this.Editor.Listeners.on(document.body, 'keydown', event => {
Copy link
Member

Choose a reason for hiding this comment

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

Точно необходимо вешать на body?

*/
enterPressed(event) {

event.preventDefault();
Copy link
Member

Choose a reason for hiding this comment

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

Оставь @todo, надо будет проверять настройку плагина allowLinebreaks

}

/**
* Hand right and down keyboard keys
Copy link
Member

Choose a reason for hiding this comment

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

handle?

}

/**
* Insert new block with data below current block
Copy link
Member

Choose a reason for hiding this comment

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

Функция же не только для этого

*/
prepare() {

this.Editor.Listeners.on(document.body, 'keydown', event => {
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.

меня это тоже смущает, потому что один keydown на весь редактор. Можно это сделать при формировании блока (в BlockManager#composeBlock) - вешать событие здесь.

@codex-team codex-team deleted a comment from gohabereg Jan 8, 2018
let block = this.composeBlock(toolName, data);

this._blocks[++this.currentBlockIndex] = block;
this.Editor.Caret.setToBlock(block);

}

/**
* Create new block below current block and insert extracted content form current block to new block
Copy link
Member

Choose a reason for hiding this comment

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

Очень сложно. В таких случаях лучше писать прям по пунктам

Split current block 
1. Extract content from caret position to block`s end
2. Insert new block below current one with extracted content

@@ -116,4 +116,28 @@ export default class Caret extends Module {

}

/**
* Extract content fragment of current block form caret position
Copy link
Member

Choose a reason for hiding this comment

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

... from caret position to the end of the block

* @class Keyboard
* @classdesc Сlass to handle the keystrokes
*
* @module Keyboard
Copy link
Member

Choose a reason for hiding this comment

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

Это можно убрать

* @author CodeX Team (team@ifmo.su)
* @copyright CodeX Team 2017
* @license The MIT License (MIT)
* @version 2.0.0
Copy link
Member

Choose a reason for hiding this comment

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

Это новый класс, 1 версия

}

/**
* Handler on Editor for keyboard keys at keydown event
Copy link
Member

Choose a reason for hiding this comment

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

Что такое Editor в этом контексте?
И обработчик ты на блок же вешаешь

enterPressed(event) {

/**
* @todo check settings of "allowLinebreaks" plugin
Copy link
Member

Choose a reason for hiding this comment

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

Что-то не понятно, что написано
check plugin`s configuration for allowLinebreaks property

*/
event.preventDefault();
/**
* Insert new block with data below current block
Copy link
Member

Choose a reason for hiding this comment

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

Оставь просто split current block into two ones

break;

}
this.Editor.Listeners.on(block.pluginsContent, 'keydown', (event) => this.Editor.Keyboard.keyboardListener(event));
Copy link
Member

Choose a reason for hiding this comment

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

blockKeydownsListener

let block = this.composeBlock(toolName, data);

this._blocks[++this.currentBlockIndex] = block;
this.Editor.Caret.setToBlock(block);

}

/**
* Split current block
* 1. Extract content from caret position to block`s end
Copy link
Member

Choose a reason for hiding this comment

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

to the

Copy link
Member

Choose a reason for hiding this comment

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

Caret , Block

/**
* Split current block
* 1. Extract content from caret position to block`s end
* 2. Insert new block below current one with extracted content
Copy link
Member

Choose a reason for hiding this comment

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

a new Block

wrapper.append(extractedFragment);

/**
* @todo make object in accordance with the plugin
Copy link
Member

Choose a reason for hiding this comment

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

with Tool

text: wrapper.innerHTML,
};

this.insert('text', data);
Copy link
Member

Choose a reason for hiding this comment

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

inititalTool

@@ -116,4 +116,28 @@ export default class Caret extends Module {

}

/**
* Extract content fragment of current block from caret position to the end of the block
Copy link
Member

Choose a reason for hiding this comment

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

Block, Caret,

@@ -0,0 +1,103 @@
/**
* @class Keyboard
* @classdesc Сlass to handle the keystrokes
Copy link
Member

Choose a reason for hiding this comment

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

keydowns?

}

/**
* Handler on block for keyboard keys at keydown event
Copy link
Member

Choose a reason for hiding this comment

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

Block

enterPressed(event) {

/**
* @todo check plugin`s configuration for allowLinebreaks property
Copy link
Member

Choose a reason for hiding this comment

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

Tool's

*/
event.preventDefault();
/**
* Split current block into two ones
Copy link
Member

Choose a reason for hiding this comment

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

Split the Current Block.

Copy link
Member

@neSpecc neSpecc left a comment

Choose a reason for hiding this comment

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

Некорректное поведение при попытке сплита с выделенным текстом (Safari)
https://giphy.com/gifs/3oFzmnols9OJd6AKPe

@Nikitos9I Nikitos9I merged commit c73ce70 into rewriting-version2.0 Jan 11, 2018
@Nikitos9I Nikitos9I deleted the Split-Merge-blocks branch January 11, 2018 17:45
@neSpecc neSpecc mentioned this pull request Jan 12, 2018
@Nikitos9I Nikitos9I restored the Split-Merge-blocks branch January 12, 2018 13:13
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.

4 participants