Skip to content

Commit

Permalink
Cleanup code and set selection correct in multi-refence inside an opt…
Browse files Browse the repository at this point in the history
…ional box.
joswarmer committed Nov 4, 2024
1 parent d1b35f8 commit 7f6778a
Showing 4 changed files with 28 additions and 20 deletions.
8 changes: 4 additions & 4 deletions packages/core/src/editor/actions/FreAction.ts
Original file line number Diff line number Diff line change
@@ -57,11 +57,11 @@ export abstract class FreAction {
referenceShortcut?: ReferenceShortcut;

/**
* execute the action
* @param box The selected box
* Execute the action
* @param box The selected box on which this action is executed
* @param trigger The trigger that causes this action to execute
* @param editor The editor
* @param index
* @param editor The editor
* @param index The index in the list, if there is any
*/
abstract execute(box: Box, trigger: FreTriggerUse, editor: FreEditor, index?: number): FrePostAction;
}
20 changes: 11 additions & 9 deletions packages/core/src/editor/actions/FreCustomAction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import { FreNode } from "../../ast/index.js";
import { AST } from "../../change-manager/index.js";
import { FreUtils } from "../../util/index.js";
import { Box } from "../boxes/index.js";
@@ -11,9 +10,6 @@ import {
triggerTypeToString,
ACTION_LOGGER
} from "./internal.js";
// import { FreLogger } from "../../logging";

// const LOGGER = new FreLogger("FreCustomAction");

export class FreCustomAction extends FreAction {
static create(initializer?: Partial<FreCustomAction>) {
@@ -30,7 +26,13 @@ export class FreCustomAction extends FreAction {
super();
}

execute(box: Box, trigger: FreTriggerUse, editor: FreEditor): FrePostAction {
/**
* @see FreAction.execute
* @param box
* @param trigger
* @param editor
*/
override execute(box: Box, trigger: FreTriggerUse, editor: FreEditor): FrePostAction {
ACTION_LOGGER.log("FreCustomCommand: trigger [" + triggerTypeToString(trigger) + "]");
ACTION_LOGGER.log("FreCustomCommand: action [" + this.action + "]");
const self = this;
@@ -41,25 +43,25 @@ export class FreCustomAction extends FreAction {
if (!!selected) {
if (!!self.boxRoleToSelect) {
return function () {
console.log("FreCustomCommand select " + box.node.freLanguageConcept() + " box " + self.boxRoleToSelect);
ACTION_LOGGER.log("FreCustomCommand select " + box.node.freLanguageConcept() + " box " + self.boxRoleToSelect);
editor.selectElementBox(selected, self.boxRoleToSelect, self.caretPosition);
};
} else {
// Default: select the first editable child of the selected element
return function () {
console.log("editor.selectFirstEditableChildBox(selected) ");
ACTION_LOGGER.log("editor.selectFirstEditableChildBox(selected) ");
editor.selectFirstEditableChildBox(selected);
};
}
}
console.log("Returninf REFERENCE function")
return function(): void {
// TODO "REFERENCE" is a quickfix to get the selection correct
if (self.boxRoleToSelect === "REFERENCE") {
const index = (box.node[box.propertyName] as Array<any>).length -1
// const empty = editor.findBoxForNode(box.node, box.propertyName)
editor.selectElement(box.node, box.propertyName, index)
editor.selectNextLeaf()
console.log(`REFERENCE node ${box.node.freId()} prop ${box.propertyName} index ${index}`)
ACTION_LOGGER.log(`REFERENCE node ${box.node.freId()} prop ${box.propertyName} index ${index}`)
}
}
// return EMPTY_POST_ACTION;
1 change: 0 additions & 1 deletion packages/core/src/editor/util/BehaviorUtils.ts
Original file line number Diff line number Diff line change
@@ -96,7 +96,6 @@ export function executeSingleBehavior(
execresult = action.execute(box, label, editor, index);
});
if (!!execresult) {
console.log("executeSingleBehavior post function")
execresult();
}
return BehaviorExecutionResult.EXECUTED;
Original file line number Diff line number Diff line change
@@ -134,12 +134,19 @@ export class DefaultActionsTemplate {
}
} else {
// reference
// TODO Handle List case seperately?
rolename = Roles.propertyRole(
myClassifier.name,
optionalPropertyName,
"referencebox",
);
if (prop.isList) {
rolename = Roles.propertyRole(
myClassifier.name,
optionalPropertyName,
"new-list-item"
)
} else {
rolename = Roles.propertyRole(
myClassifier.name,
optionalPropertyName,
"referencebox",
);
}
}
}
result += `${Names.FreCustomAction}.create(

0 comments on commit 7f6778a

Please sign in to comment.