Skip to content

Commit

Permalink
Fix bug when walkMarkerableSections ranges starts with card
Browse files Browse the repository at this point in the history
  • Loading branch information
bantic committed Oct 13, 2015
1 parent e64872a commit 9d6266c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/js/editor/post.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
DEFAULT_TAG_NAME as DEFAULT_MARKUP_SECTION_TAG_NAME
} from '../models/markup-section';
import { isMarkerable } from '../models/_section';
import { POST_TYPE, MARKUP_SECTION_TYPE, LIST_ITEM_TYPE } from '../models/types';
import Position from '../utils/cursor/position';
import {
Expand All @@ -22,10 +23,6 @@ function isBlankAndListItem(section) {
return isListItem(section) && section.isBlank;
}

function isMarkerable(section) {
return !!section.markers;
}

const CALLBACK_QUEUES = {
BEFORE_COMPLETE: 'beforeComplete',
COMPLETE: 'complete',
Expand Down
2 changes: 1 addition & 1 deletion src/js/models/_section.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LIST_ITEM_TYPE } from './types';
import { normalizeTagName } from '../utils/dom-utils';
import LinkedItem from '../utils/linked-item';

function isMarkerable(section) {
export function isMarkerable(section) {
return !!section.markers;
}

Expand Down
6 changes: 5 additions & 1 deletion src/js/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { POST_TYPE } from './types';
import LinkedList from 'content-kit-editor/utils/linked-list';
import { forEach, compact } from 'content-kit-editor/utils/array-utils';
import Set from 'content-kit-editor/utils/set';
import { isMarkerable } from 'content-kit-editor/models/_section';

export default class Post {
constructor() {
Expand Down Expand Up @@ -102,6 +103,10 @@ export default class Post {
const {head, tail} = range;

let currentSection = head.section;
if (!isMarkerable(currentSection)) {
currentSection = this._nextMarkerableSection(currentSection);
}

while (currentSection) {
callback(currentSection);

Expand Down Expand Up @@ -145,7 +150,6 @@ export default class Post {
// return the next section that has markers after this one
_nextMarkerableSection(section) {
if (!section) { return null; }
const isMarkerable = s => !!s.markers;
const hasChildren = s => !!s.items;
const firstChild = s => s.items.head;
const isChild = s => s.parent && !s.post;
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/models/post-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ test('#markersFrom finds markers across non-homogeneous sections', (assert) => {
'iterates correct markers');
});

test('#walkMarkerableSections finds no section when range contains only a card', (assert) => {
const post = Helpers.postAbstract.build(builder => {
const {post, cardSection} = builder;

return post([cardSection('simple-card')]);
});

let foundSections = [];

const card = post.sections.objectAt(0);
const range = Range.create(card, 0, card, 0);

post.walkMarkerableSections(range, s => foundSections.push(s));
assert.equal(foundSections.length, 0, 'found no markerable sections');
});

test('#walkMarkerableSections skips non-markerable sections', (assert) => {
const post = Helpers.postAbstract.build(builder => {
const {post, markupSection, marker, cardSection} = builder;
Expand Down

0 comments on commit 9d6266c

Please sign in to comment.