Skip to content

Commit

Permalink
Merge pull request #402 from freon4dsl/fix-selection-in-reference-list
Browse files Browse the repository at this point in the history
Fix selection in reference list
  • Loading branch information
joswarmer authored Nov 4, 2024
2 parents 90c774e + 7f6778a commit bdd4f81
Show file tree
Hide file tree
Showing 24 changed files with 528 additions and 467 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
* It is called from the box.
*/
export async function setFocus(): Promise<void> {
LOGGER.log("setFocus "+ id + " input is there: " + !!inputElement);
console.log("TextComponent.setFocus "+ id + " input is there: " + !!inputElement);
if (!!inputElement) {
inputElement.focus();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
* This function sets the focus on this element programmatically.
*/
const setFocus = () => {
LOGGER.log("setFocus " + box.kind + id);
console.log("TextDropdownComponent.setFocus " + box.kind + id);
if (!!textComponent) {
textComponent.setFocus();
} else {
Expand Down Expand Up @@ -359,7 +359,14 @@
isEditing = false;
dropdownShown = false;
box.executeOption(editor, selected); // TODO the result of the execution is ignored
const post = box.executeOption(editor, selected); // TODO the result of the execution is ignored
if (!!post) {
if (typeof post === "function") {
post()
} else {
console.log("POST is noit a function: " + post)
}
}
if (isActionBox(box)) { // ActionBox, action done, clear input text
setTextLocalAndInBox('');
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AST, Box, FRE_NULL_COMMAND, FreLogger, FreCommand, FreEditor, FreEditorUtil, type FrePostAction, toFreKey } from "@freon4dsl/core";
import { AST, Box, FreLogger, FreEditor, FreEditorUtil, type FrePostAction, toFreKey, FreAction } from "@freon4dsl/core";
import { viewport } from "./EditorViewportStore.js";
import { get } from "svelte/store";

Expand Down Expand Up @@ -46,8 +46,8 @@ export function calculatePos(viewportSize: number, contentSize: number, mousePos
}

export function executeCustomKeyboardShortCut(event: KeyboardEvent, index: number, box: Box, editor: FreEditor) {
const cmd: FreCommand = FreEditorUtil.findKeyboardShortcutCommand(toFreKey(event), box, editor);
if (cmd !== FRE_NULL_COMMAND) {
const cmd: FreAction = FreEditorUtil.findKeyboardShortcutAction(toFreKey(event), box, editor);
if (cmd !== null) {
let postAction: FrePostAction;
AST.change(() => {
// todo KeyboardEvent does not have an "action" prop, so what is happening here?
Expand Down
16 changes: 12 additions & 4 deletions packages/core/src/editor/actions/FreAction.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { FreNode } from "../../ast/index.js";
import { FreLogger } from "../../logging/index.js";
import { FreCaret } from "../util/index.js";
import { Box } from "../boxes/index.js";
import { FreEditor } from "../FreEditor.js";
import { FreCommand } from "./FreCommand.js";
import { FreTriggerUse, FreTriggerType } from "./FreTriggers.js";

export const ACTION_LOGGER = new FreLogger("FreAction")

export type CustomAction = (box: Box, trigger: FreTriggerUse, editor: FreEditor) => FreNode | null;
export type FrePostAction = () => void;

/**
* Use this if there is no post action.
*/
export const EMPTY_POST_ACTION = function () {
/* todo create this function body */
};

export type ReferenceShortcut = {
Expand Down Expand Up @@ -53,7 +57,11 @@ export abstract class FreAction {
referenceShortcut?: ReferenceShortcut;

/**
* Returns the command object that can be executed to perform the action.
* 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 The index in the list, if there is any
*/
abstract command(): FreCommand;
abstract execute(box: Box, trigger: FreTriggerUse, editor: FreEditor, index?: number): FrePostAction;
}
54 changes: 0 additions & 54 deletions packages/core/src/editor/actions/FreCommand.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { FreBinaryExpression } from "../../ast/index.js";
import { FreUtils } from "../../util/index.js";
import { AST } from "../../change-manager/index.js";
import { BTREE, FRE_BINARY_EXPRESSION_LEFT, FreUtils, Selected } from "../../util/index.js";
import { Box } from "../boxes/index.js";
import { FreEditor } from "../FreEditor.js";
import { FreAction } from "./FreAction.js";
import { FreCommand } from "./FreCommand.js";
import { FreCreateBinaryExpressionCommand } from "./FreCreateBinaryExpressionCommand.js";
import { ACTION_LOGGER, FreAction, FrePostAction } from "./FreAction.js";
import { FreTriggerUse, triggerTypeToString } from "./FreTriggers.js";


export class FreCreateBinaryExpressionAction extends FreAction {
Expand All @@ -22,7 +22,30 @@ export class FreCreateBinaryExpressionAction extends FreAction {
super();
}

command(): FreCommand {
return new FreCreateBinaryExpressionCommand(this.expressionBuilder);
execute(box: Box, trigger: FreTriggerUse, editor: FreEditor): FrePostAction {
// console.log("FreCreateBinaryExpressionCommand: trigger [" + triggerTypeToString(trigger) + "] part: ");
let selected: Selected
AST.change( () => {
selected = BTREE.insertBinaryExpression(
this.expressionBuilder(box, triggerTypeToString(trigger), editor),
box,
editor,
);
})
// TODO Check whether this fix works consistently correct.
const childProperty = selected.boxRoleToSelect === FRE_BINARY_EXPRESSION_LEFT ? "left" : "right";
return function () {
ACTION_LOGGER.log(
"FreCreateBinaryExpressionCommand select after: " +
selected.element.freLanguageConcept() +
" ID " +
selected.element.freId() +
" rolr " +
childProperty,
);
editor.selectElement(selected.element, childProperty);
editor.selectFirstEditableChildBox(selected.element);
};
}

}

This file was deleted.

83 changes: 77 additions & 6 deletions packages/core/src/editor/actions/FreCreatePartAction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { FreUtils } from "../../util/index.js";
import { FreAction } from "./FreAction.js";
import { FreCommand } from "./FreCommand.js";
import { FreCreatePartCommand } from "./FreCreatePartCommand.js";
import { FreBinaryExpression, FreNode } from "../../ast/index.js";
import { FreLanguage } from "../../language/index.js";
import { BTREE, FreUtils } from "../../util/index.js";
import { Box } from "../boxes/index.js";
import { FreEditor } from "../FreEditor.js";
import { ACTION_LOGGER, EMPTY_POST_ACTION, FreAction, FrePostAction } from "./FreAction.js";
import { FreTriggerUse, isString, triggerTypeToString } from "./FreTriggers.js";

// import { FreLogger } from "../../logging";
// const LOGGER = new FreLogger("FreCreateElementAction");
Expand All @@ -22,7 +25,75 @@ export class FreCreatePartAction extends FreAction {
FreUtils.initializeObject(this, initializer);
}

command(): FreCommand {
return new FreCreatePartCommand(this.propertyName, this.conceptName, this.referenceShortcut);
/**
*
* @param box
* @param trigger
* @param editor
* @param index If the property is a list, the index in the list at which the created element will be stored.
*/
execute(box: Box, trigger: FreTriggerUse, editor: FreEditor, index?: number): FrePostAction {
// todo make index optional and set the default value to -1;
ACTION_LOGGER.log(
"CreatePartCommand: trigger [" +
triggerTypeToString(trigger) +
"] part: " +
this.conceptName +
" in " +
this.propertyName +
" index " +
index +
" refshort " +
this.referenceShortcut +
" parentbox " +
box?.node?.freLanguageConcept(),
);
const ownerConcept: string = box.node.freLanguageConcept();
const propName: string = this.propertyName;
const theModelElement = box.node[propName];

const newElement: FreNode = FreLanguage.getInstance().classifier(this.conceptName)?.creator({});
if (newElement === undefined || newElement === null) {
// TODO Find out why this happens sometimes
ACTION_LOGGER.error("ActionBox action: Unexpected new element undefined");
return EMPTY_POST_ACTION;
}
ACTION_LOGGER.log(
`FreCreatePartCommand: setting/adding to ${propName} of ${box.node.freId()} (${box.node.freLanguageConcept()}) to ${newElement.freId()} (${newElement.freLanguageConcept()})`,
);
if (FreLanguage.getInstance().classifierProperty(ownerConcept, propName).isList) {
if (index >= 0) {
theModelElement.splice(index, 0, newElement);
} else {
theModelElement.push(newElement);
}
} else {
box.node[propName] = newElement;
}
if (!!trigger && isString(trigger) && !!this.referenceShortcut) {
newElement[this.referenceShortcut.propertyName] = FreLanguage.getInstance().referenceCreator(
trigger,
this.referenceShortcut.conceptName,
);
}
// Always rebalance for a binary expression
if (newElement.freIsBinaryExpression()) {
BTREE.balanceTree(newElement as FreBinaryExpression, editor);
}
return function () {
// editor.selectElement(newElement);
// tslint:disable-next-line:max-line-length
ACTION_LOGGER.log(
"CreatePartCommand: newElement:" +
newElement.freId() +
" " +
newElement.freLanguageConcept() +
", selected element: " +
editor.selectedBox.node.freId() +
" of kind " +
editor.selectedBox.kind,
);
editor.selectFirstEditableChildBox(newElement, true);
};
}
}
Loading

0 comments on commit bdd4f81

Please sign in to comment.