Skip to content

Commit

Permalink
Merge pull request #145 from bustlelabs/block-format-post-editor
Browse files Browse the repository at this point in the history
Use postEditor for block format commands
  • Loading branch information
bantic committed Sep 16, 2015
2 parents 0eb505b + 0e4befd commit 243a465
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 42 deletions.
33 changes: 14 additions & 19 deletions src/js/commands/format-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,25 @@ class FormatBlockCommand extends TextFormatCommand {
}

exec() {
const editor = this.editor;
const activeSections = editor.activeSections;

activeSections.forEach(s => {
editor.resetSectionMarkers(s);
editor.setSectionTagName(s, this.tag);
const { editor } = this;
editor.run(postEditor => {
const activeSections = editor.activeSections;
activeSections.forEach(s => postEditor.changeSectionTagName(s, this.tag));
postEditor.scheduleAfterRender(() => {
editor.selectSections(activeSections);
});
});

editor.rerender();
editor.selectSections(activeSections);
this.editor.didUpdate();
}

unexec() {
const editor = this.editor;
const activeSections = editor.activeSections;

activeSections.forEach(s => {
editor.resetSectionTagName(s);
const { editor } = this;
editor.run(postEditor => {
const activeSections = editor.activeSections;
activeSections.forEach(s => postEditor.resetSectionTagName(s));
postEditor.scheduleAfterRender(() => {
editor.selectSections(activeSections);
});
});

editor.rerender();
editor.selectSections(activeSections);
this.editor.didUpdate();
}
}

Expand Down
23 changes: 0 additions & 23 deletions src/js/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,29 +371,6 @@ class Editor {
}
}

/*
* Clear the markups from each of the section's markers
*/
resetSectionMarkers(section) {
section.markers.forEach(m => {
m.clearMarkups();
m.renderNode.markDirty();
});
}

/*
* Change the tag name for the given section
*/
setSectionTagName(section, tagName) {
section.setTagName(tagName);
section.renderNode.markDirty();
}

resetSectionTagName(section) {
section.resetTagName();
section.renderNode.markDirty();
}

_reparseCurrentSection() {
const {headSection:currentSection } = this.cursor.offsets;
this._parser.reparseSection(currentSection, this._renderTree);
Expand Down
16 changes: 16 additions & 0 deletions src/js/editor/post.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import {
DEFAULT_TAG_NAME as DEFAULT_MARKUP_SECTION_TAG_NAME
} from '../models/markup-section';
import { POST_TYPE, MARKUP_SECTION_TYPE, LIST_ITEM_TYPE } from '../models/types';
import Position from '../utils/cursor/position';
import { any, filter, compact } from '../utils/array-utils';
Expand Down Expand Up @@ -596,6 +599,19 @@ class PostEditor {
this.scheduleAfterRender(() => this.editor.selectRange(range));
}

changeSectionTagName(section, newTagName) {
section.markers.forEach(m => {
m.clearMarkups();
this._markDirty(m);
});
section.setTagName(newTagName);
this._markDirty(section);
}

resetSectionTagName(section) {
this.changeSectionTagName(section, DEFAULT_MARKUP_SECTION_TAG_NAME);
}

/**
* Insert a given section before another one, updating the post abstract
* and the rendered UI.
Expand Down

0 comments on commit 243a465

Please sign in to comment.