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

Поправил определение границ ссылки #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Epsilonnnn
Copy link

Убрал функции, приводящии к разбиению текстовых нод

@Epsilonnnn
Copy link
Author

Epsilonnnn commented Jun 7, 2018

Проблема 1: Операции CKEDITOR.dom.range.checkStartOfBlock и CKEDITOR.dom.range.checkEndOfBlock меняют текстовые ноды и могут разделять одну тектовую ноду на 2 части, из-за этого при клике в любую тектовую ноду она разделяется на 2.

Проблема 2: Операции CKEDITOR.dom.range.checkStartOfBlock и CKEDITOR.dom.range.checkEndOfBlock не определяют корректно конец и начало ссылки, а определяют на самом деле конец и начало первого дива, в который обёрнута ссылка.

Решение: Заменил CKEDITOR.dom.range.checkStartOfBlock и CKEDITOR.dom.range.checkEndOfBlock на более точную функцию определения границ ссылки, которая не модифицирует DOM.

Copy link
Member

@chestozo chestozo left a comment

Choose a reason for hiding this comment

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

вопросики

abbr: 1, acronym: 1, b: 1, bdo: 1, big: 1, cite: 1, code: 1, del: 1,
dfn: 1, em: 1, font: 1, i: 1, ins: 1, label: 1, kbd: 1, q: 1, samp: 1, small: 1, span: 1, strike: 1,
strong: 1, sub: 1, sup: 1, tt: 1, u: 1, 'var': 1
};
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
Author

Choose a reason for hiding this comment

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

Реализация функции linkStartEndEvaluator была inspired by вот этой функцией https://github.com/yandex-ui/ckeditor-dev/blob/master/core/dom/range.js#L525 , которая используется как evaluator для функций CKEDITOR.dom.range.checkStartOfBlock и CKEDITOR.dom.range.checkEndOfBlock.

Список взят отсюда - https://github.com/yandex-ui/ckeditor-dev/blob/master/core/dom/range.js#L517

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
Author

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.

ну это же набор инлайн тэгов, похоже на статическую информацию
чтобы можно было реиспользовать

Copy link
Author

@Epsilonnnn Epsilonnnn Jun 13, 2018

Choose a reason for hiding this comment

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

Ты говоришь про проектный конфиг? Тоесть вынести этот список из плагина?
я не думаю, что это нужно будет переиспользовать, так же тут теги не всех inline элементов
Кажется, имеет смысл выносить, только если это реально где-то понадобится, тоесть, если где-то ещё придётся писать свою функцию определения начала и/или конца блока

plugin.js Outdated
}

var isFalseTextNode = node.type == ckeditorNamespace.NODE_TEXT &&
!node.hasAscendant('pre') && !ckeditorNamespace.tools.trim(node.getText()).length;
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.

почему именно pre?

Copy link
Author

Choose a reason for hiding this comment

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

взято отсюда - https://github.com/yandex-ui/ckeditor-dev/blob/master/core/dom/range.js#L543
на сколько я понимаю pre должно передавать юзер-инпут без изменений даже если это пробелы, поэтому с ним считаются

кажется, замечание про === резонно, можно поправить

plugin.js Outdated
var isFalseTextNode = node.type == ckeditorNamespace.NODE_TEXT &&
!node.hasAscendant('pre') && !ckeditorNamespace.tools.trim(node.getText()).length;

var isFalseInlineBlock = node.type == ckeditorNamespace.NODE_ELEMENT && node.is(inlineChildReqElements);
Copy link
Member

Choose a reason for hiding this comment

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

не хотим оптимизнуть и не вычислять node.is(), пока это не требуется?

Copy link
Author

Choose a reason for hiding this comment

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

поправил

plugin.js Outdated
@@ -14,26 +49,29 @@
this.editable().on('click', this.plugins.openlink.onClick, this, null, 0);
},

_isInLinkBoundary: function(range, link) {
var prevNode = range.getPreviousNode(linkStartEndEvaluator(CKEDITOR), linkStartEndGuard(link), link);
var nextNode = range.getNextNode(linkStartEndEvaluator(CKEDITOR), linkStartEndGuard(link), link);
Copy link
Member

Choose a reason for hiding this comment

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

аналогично, можно оптимизнуть и не вычислять nextNode, если это не нужно

Copy link
Author

Choose a reason for hiding this comment

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

поправил

return;
}

var nativeEvent = event.data.$;
var path = new CKEDITOR.dom.elementPath(new CKEDITOR.dom.element(nativeEvent.target), range.root);

var link = path.contains('a', true);
if (!link) {
if (!link || this.plugins.openlink._isInLinkBoundary(range, link)) {
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
Author

@Epsilonnnn Epsilonnnn Jun 8, 2018

Choose a reason for hiding this comment

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

метод принадлежит плагину, внутри которого вызывается

plugin.js Outdated
!node.hasAscendant('pre') && !ckeditorNamespace.tools.trim(node.getText()).length;

var isFalseInlineBlock = node.type == ckeditorNamespace.NODE_ELEMENT && node.is(inlineChildReqElements);
// is false inline block
Copy link
Member

Choose a reason for hiding this comment

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

is not inline block
а вообще можно было бы сделать переменную и тогда коммент не нужен
!isInlineBlock

Copy link
Author

Choose a reason for hiding this comment

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

не все inline блоки, нет например img

Copy link
Member

Choose a reason for hiding this comment

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

разве img не inline?

Copy link
Author

Choose a reason for hiding this comment

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

да, inline, но тут его специально нет - https://github.com/yandex-ui/ckeditor-dev/blob/master/core/dom/range.js#L549

plugin.js Outdated

if (isFalseTextNode || isFalseInlineBlock) {
// is false text node
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
Author

@Epsilonnnn Epsilonnnn Jun 13, 2018

Choose a reason for hiding this comment

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

наверное стоит написать is empty text node

abbr: 1, acronym: 1, b: 1, bdo: 1, big: 1, cite: 1, code: 1, del: 1,
dfn: 1, em: 1, font: 1, i: 1, ins: 1, label: 1, kbd: 1, q: 1, samp: 1, small: 1, span: 1, strike: 1,
strong: 1, sub: 1, sup: 1, tt: 1, u: 1, 'var': 1
};
Copy link
Member

Choose a reason for hiding this comment

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

может его его в конфиг можно положить?

plugin.js Outdated
}

// is false inline block
if (node.type == ckeditorNamespace.NODE_ELEMENT && node.is(inlineChildReqElements)) {
Copy link
Member

Choose a reason for hiding this comment

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

проверка "это inline node-а"
а коммент как будто бы про другое ..

Copy link
Member

Choose a reason for hiding this comment

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

Имхо коммент выше не нужен, он почти полностью дублирует код.
Может стоит переименовать inlineChildReqElements во что-то более говорящее (не очень ясно, что значит req).

Copy link
Author

Choose a reason for hiding this comment

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

добавил коммент про inlineChildReqElements - https://github.com/yandex-ui/ckeditor-openlink/pull/1/files#diff-18e559ebd3cc204a52bc1dc3db2adf8bR6

req - require

plugin.js Outdated
}

// is false inline block
if (node.type == ckeditorNamespace.NODE_ELEMENT && node.is(inlineChildReqElements)) {
Copy link
Member

Choose a reason for hiding this comment

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

Имхо коммент выше не нужен, он почти полностью дублирует код.
Может стоит переименовать inlineChildReqElements во что-то более говорящее (не очень ясно, что значит req).

plugin.js Outdated
if (
node.type == ckeditorNamespace.NODE_TEXT && !node.hasAscendant('pre') &&
!ckeditorNamespace.tools.trim(node.getText()).length
) {
Copy link
Member

Choose a reason for hiding this comment

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

имхо тут стоит

  • проверку node.hasAscendant() делать в самую последнюю очередь (как самую дорогую)
  • коммент, имхо, стоит переписать на что-то более human readable, сейчас я не очень понимаю вообще что делает linkStartEndEvaluator поэтому не могу предложить чего-то конкретного )

Copy link
Author

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.

я всё ещё не доволен комментом
он нам говорит "это пустая текстовая нода"
а проверка на непустоту !ckeditorNamespace.tools.trim(node.getText()).length

Copy link
Author

@Epsilonnnn Epsilonnnn Jun 14, 2018

Choose a reason for hiding this comment

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

эм, если ckeditorNamespace.tools.trim(node.getText()).length = 0, то !ckeditorNamespace.tools.trim(node.getText()).length = true ))

Убрал функции, приводящии к разбиению текстовых нод
@Epsilonnnn Epsilonnnn force-pushed the fix-detect-link-boundaries branch from 2441dcd to 7368d2a Compare June 15, 2018 11:06
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.

2 participants