2017-03-02 19:51:57 +03:00
|
|
|
import Component from 'ember-component';
|
2017-03-01 22:23:03 +03:00
|
|
|
import layout from '../templates/components/koenig-menu-item';
|
2017-02-27 07:44:15 +03:00
|
|
|
import Range from 'mobiledoc-kit/utils/cursor/range';
|
|
|
|
|
2017-03-02 19:51:57 +03:00
|
|
|
export default Component.extend({
|
2017-02-27 07:44:15 +03:00
|
|
|
layout,
|
|
|
|
tagName: 'li',
|
2017-03-02 19:51:57 +03:00
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
},
|
|
|
|
|
2017-02-27 07:44:15 +03:00
|
|
|
actions: {
|
2017-03-02 19:51:57 +03:00
|
|
|
select() {
|
2017-02-27 07:44:15 +03:00
|
|
|
let {section, startOffset, endOffset} = this.get('range');
|
|
|
|
window.getSelection().removeAllRanges();
|
|
|
|
|
2017-03-02 19:51:57 +03:00
|
|
|
let range = document.createRange();
|
2017-02-27 07:44:15 +03:00
|
|
|
|
2017-03-02 19:51:57 +03:00
|
|
|
range.setStart(section.renderNode._element, 0); // startOffset-1); // todo
|
|
|
|
range.setEnd(section.renderNode._element, 0); // endOffset-1);
|
2017-02-27 07:44:15 +03:00
|
|
|
|
2017-03-02 19:51:57 +03:00
|
|
|
let selection = window.getSelection();
|
2017-02-27 07:44:15 +03:00
|
|
|
selection.addRange(range);
|
|
|
|
|
2017-03-02 19:51:57 +03:00
|
|
|
// TODO: remove console.log
|
|
|
|
// eslint-disable-next-line no-console
|
2017-02-27 07:44:15 +03:00
|
|
|
console.log(startOffset, endOffset, Range);
|
2017-03-02 19:51:57 +03:00
|
|
|
// let editor = this.get('editor');
|
|
|
|
// let range = editor.range;
|
|
|
|
// console.log(endOffset, startOffset);
|
|
|
|
// range = range.extend(endOffset - startOffset);
|
|
|
|
// editor.run((postEditor) => {
|
|
|
|
// let position = postEditor.deleteRange(range);
|
|
|
|
// let em = postEditor.builder.createMarkup('em');
|
|
|
|
// let nextPosition = postEditor.insertTextWithMarkup(position, 'BOO', [em]);
|
|
|
|
// postEditor.insertTextWithMarkup(nextPosition, '', []); // insert the un-marked-up space
|
|
|
|
// });
|
2017-02-27 07:44:15 +03:00
|
|
|
|
|
|
|
this.get('tool').onClick(this.get('editor'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|