Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
abeforgit committed Apr 27, 2022
2 parents 488c6bc + e254c0f commit a611ac4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
6 changes: 5 additions & 1 deletion addon/commands/make-list-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ModelTreeWalker from '@lblod/ember-rdfa-editor/model/util/model-tree-walk
import ModelPosition from '@lblod/ember-rdfa-editor/model/model-position';
import { PropertyState } from '../model/util/types';
import { logExecute } from '@lblod/ember-rdfa-editor/utils/logging-utils';
import ModelText from '../model/model-text';

/**
* Command will convert all nodes in the selection to a list, if they are not already in a list.
Expand Down Expand Up @@ -146,7 +147,7 @@ export default class MakeListCommand extends Command {
}

const confinedRanges = range.getMinimumConfinedRanges();
const result = [[]];
const result: ModelNode[][] = [[]];
let pos = 0;

for (const range of confinedRanges) {
Expand All @@ -165,6 +166,9 @@ export default class MakeListCommand extends Command {
}
}
}
if (result[0].length === 0) {
result[0].push(new ModelText());
}

return result;
}
Expand Down
3 changes: 3 additions & 0 deletions addon/model/model-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ export default class ModelRange {
}

static fromAroundNode(node: ModelNode) {
if (!node.parent) {
throw new IllegalArgumentError('Cannot create a range around the root');
}
const start = ModelPosition.fromBeforeNode(node);
const end = ModelPosition.fromAfterNode(node);
return new ModelRange(start, end);
Expand Down
9 changes: 8 additions & 1 deletion addon/model/util/datastore/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,14 @@ export class EditorStore implements Datastore {
mapping = this.asObjectNodeMapping();
}
for (const node of mapping.nodes()) {
const searchRange = ModelRange.fromAroundNode(node);
let searchRange;
// we test if the node is root, which will be the case when the
// rdfa knowledge is defined above the document root.
if (node.parent) {
searchRange = ModelRange.fromAroundNode(node);
} else {
searchRange = ModelRange.fromInNode(node);
}
results.push(...matchText(searchRange, regex));
}
return results;
Expand Down
2 changes: 1 addition & 1 deletion addon/model/util/gen-tree-walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ export default class GenTreeWalker<T extends Walkable = Walkable> {
// There is a currentNode, so we can simply walk from it
next = this.walkNode(this._currentNode, this._reverse);
}

// whatever we found is now the currentNode
this._currentNode = next;
if (!next) {
Expand Down Expand Up @@ -391,6 +390,7 @@ export default class GenTreeWalker<T extends Walkable = Walkable> {
}
result = this.filterNode(node);
if (result === FilterResult.FILTER_ACCEPT) {
if (node === fromNode) return null;
return node as T | null;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/commands/make-list-command-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module('Unit | commands | make-list-command', (hooks) => {
const { root: expected } = vdom`
<modelRoot>
<ul>
<li></li>
<li><text></text></li>
</ul>
</modelRoot>
`;
Expand All @@ -49,7 +49,7 @@ module('Unit | commands | make-list-command', (hooks) => {
<modelRoot>
<text>${'\n'}</text>
<ul>
<li></li>
<li><text></text></li>
</ul>
</modelRoot>
`;
Expand Down

0 comments on commit a611ac4

Please sign in to comment.