diff --git a/addon/commands/make-list-command.ts b/addon/commands/make-list-command.ts index 7b4239243..51598a602 100644 --- a/addon/commands/make-list-command.ts +++ b/addon/commands/make-list-command.ts @@ -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. @@ -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) { @@ -165,6 +166,9 @@ export default class MakeListCommand extends Command { } } } + if (result[0].length === 0) { + result[0].push(new ModelText()); + } return result; } diff --git a/addon/model/model-range.ts b/addon/model/model-range.ts index 5c2c53fb2..2b65acf2f 100644 --- a/addon/model/model-range.ts +++ b/addon/model/model-range.ts @@ -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); diff --git a/addon/model/util/datastore/datastore.ts b/addon/model/util/datastore/datastore.ts index 8da2d8257..17cc68a07 100644 --- a/addon/model/util/datastore/datastore.ts +++ b/addon/model/util/datastore/datastore.ts @@ -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; diff --git a/addon/model/util/gen-tree-walker.ts b/addon/model/util/gen-tree-walker.ts index a39df8a5a..1f3515269 100644 --- a/addon/model/util/gen-tree-walker.ts +++ b/addon/model/util/gen-tree-walker.ts @@ -295,7 +295,6 @@ export default class GenTreeWalker { // 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) { @@ -391,6 +390,7 @@ export default class GenTreeWalker { } result = this.filterNode(node); if (result === FilterResult.FILTER_ACCEPT) { + if (node === fromNode) return null; return node as T | null; } diff --git a/tests/unit/commands/make-list-command-test.ts b/tests/unit/commands/make-list-command-test.ts index b67c5cbda..5638807b1 100644 --- a/tests/unit/commands/make-list-command-test.ts +++ b/tests/unit/commands/make-list-command-test.ts @@ -23,7 +23,7 @@ module('Unit | commands | make-list-command', (hooks) => { const { root: expected } = vdom`
    -
  • +
`; @@ -49,7 +49,7 @@ module('Unit | commands | make-list-command', (hooks) => { ${'\n'}
    -
  • +
`;