Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please resolve this conflict. There shouldn't be a change to package-lock.json.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 21 additions & 21 deletions src/components/editor/EvaluateView.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
import Evaluate from '@nodes/Evaluate';
import Input from '@nodes/Input';
import type Bind from '../../nodes/Bind';
import Token from '../../nodes/Token';
import { getCaret, getIsBlocks, getProject } from '../project/Contexts';
Expand Down Expand Up @@ -50,22 +49,13 @@
if (given === undefined) {
nextBind = expected;
if ($blocks) {
const lastLeaf = node.getLastLeaf() ?? node.close;
menuPosition =
lastLeaf instanceof Token
? $caret.source.getTokenTextPosition(
lastLeaf,
)
: undefined;
menuPosition = typeof $caret.position === 'number'
? $caret.position
: undefined;
} else {
const lastLeaf = (
node.getLastInput() ?? node.open
).getLastLeaf();
menuPosition =
lastLeaf instanceof Token
? $caret.source.getTokenLastPosition(
lastLeaf,
)
// Use the caret's current position instead of the last leaf
menuPosition = typeof $caret.position === 'number'
? $caret.position
: undefined;
}
break;
Expand All @@ -81,9 +71,17 @@
<NodeView node={node.fun} /><NodeView node={node.types} /><NodeView
node={node.open}
/>
{#each node.inputs as input}<NodeView node={input} /><PlaceholderView
<!-- {#each node.inputs as input}<NodeView node={input} /><PlaceholderView
position={input instanceof Input ? input.value : input}
/>{/each}<!-- {#if nextBind}
/>{/each} -->
<!-- {#each node.inputs as input}<NodeView
node={input}
/>{/each} -->
{#each node.inputs as input}<NodeView node={input} /><PlaceholderView
position={input}
/>{/each}

<!-- {#if nextBind}
<div class="hint"
><div class="name"
><RootView
Expand All @@ -102,9 +100,11 @@
{:else}
<NodeView node={node.fun} /><NodeView node={node.types} /><NodeView
node={node.open}
/>{#each node.inputs as input}<NodeView
node={input}
/>{/each}<!-- {#if nextBind}
/>{#each node.inputs as input}<NodeView node={input} /><PlaceholderView
position={input}
/>{/each}

<!-- {#if nextBind}
<div class="hint"
><div class="name"
><RootView
Expand Down
9 changes: 9 additions & 0 deletions src/edit/Append.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ export default class Append<NodeType extends Node> extends Revision {
// Does the insertion have a placeholder token? If so, place the caret at it's first placeholder instead of the end.
const firstPlaceholder = newChild.getFirstPlaceholder();
if (firstPlaceholder) newCaretPosition = firstPlaceholder;

// // Keep the caret at the original insertion position
// let newCaretPosition: Node | number | undefined = this.position;

// // Only move to placeholder if explicitly requested (e.g., for completions)
// if (this.isCompletion()) {
// const firstPlaceholder = newChild.getFirstPlaceholder();
// if (firstPlaceholder) newCaretPosition = firstPlaceholder;
// }

// Return the new source and put the caret immediately after the inserted new child.
return [
Expand Down
57 changes: 33 additions & 24 deletions src/edit/Assign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export default class Assign<NodeType extends Node> extends Revision {
return node === undefined
? undefined
: node instanceof Node
? node
: node.getNode(locales);
? node
: node.getNode(locales);
}

getEditedNode(locales: Locales): [Node, Node] {
Expand All @@ -68,21 +68,21 @@ export default class Assign<NodeType extends Node> extends Revision {
const existingChild = this.parent.getField(this.additions[0].field);
const originalPosition = existingChild
? this.context.source.getNodeFirstPosition(
Array.isArray(existingChild)
? existingChild[0]
: existingChild,
)
Array.isArray(existingChild)
? existingChild[0]
: existingChild,
)
: undefined;

// Split the space using the position, defaulting to the original space.
const newSpaces =
newNode === undefined
? this.context.source.spaces
: Revision.splitSpace(
this.context.source,
this.position,
newNode,
);
this.context.source,
this.position,
newNode,
);

let newSource = this.context.source
.replace(this.parent, newParent)
Expand All @@ -94,26 +94,35 @@ export default class Assign<NodeType extends Node> extends Revision {
getPreferredSpaces(newParent, newSource.spaces),
);

// Place the caret at first placeholder or the end of the node in the source.
// // Place the caret at first placeholder or the end of the node in the source.
// const newCaretPosition =
// newNode === undefined
// ? (originalPosition ?? this.position)
// : (newParent.getFirstPlaceholder() ??
// newSource.getNodeLastPosition(newNode));

// Keep caret at original position unless this is a completion
const newCaretPosition =
newNode === undefined
? (originalPosition ?? this.position)
: (newParent.getFirstPlaceholder() ??
newSource.getNodeLastPosition(newNode));
: this.isCompletion()
? (newParent.getFirstPlaceholder() ??
newSource.getNodeLastPosition(newNode))
: this.position;

// If we didn't find a caret position, bail. Otherwise, return the edit.
return newCaretPosition === undefined
? undefined
: [
newSource,
new Caret(
newSource,
newCaretPosition,
undefined,
undefined,
newNode,
),
];
newSource,
new Caret(
newSource,
newCaretPosition,
undefined,
undefined,
newNode,
),
];
}

getDescription(locales: Locales) {
Expand Down Expand Up @@ -141,9 +150,9 @@ export default class Assign<NodeType extends Node> extends Revision {
(node === undefined
? otherNode === undefined
: node instanceof Node
? otherNode instanceof Node &&
? otherNode instanceof Node &&
node.isEqualTo(otherNode)
: otherNode instanceof Refer &&
: otherNode instanceof Refer &&
node.equals(otherNode))
);
})
Expand Down
Loading