Allow switching a property-less mark (e.g. bold) to a link
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- frontend
Research direction
Start in src/routes/commands.svelte.ts, then read src/lib/doc_utils.ts and the generic ToggleMarkCommand switch path. Verify whether toggle_mark('link', { href }) displaces a touched property-less mark and determine the intended behavior for partially touched marks. Add focused coverage for switching to a link and confirm the reverse direction remains blocked.
Written by the indexing model from the issue text.
Description
Current behavior
Mark switching is asymmetric today, but not in the way you'd expect — both directions between bold and link are blocked, by two different mechanisms:
- link → bold is blocked by
can_switch_mark_type(src/lib/doc_utils.ts), which only allows switching when both mark types are property-less. Link carrieshref, so converting away from a link is refused. This is deliberate data-loss protection and should stay. - bold → link is blocked by a blunter rule:
ToggleLinkCommand.is_enabled(src/routes/commands.svelte.ts) requires!selection_touches_marksfor link creation. Any touched mark — even a property-less bold — disables the link button. The "replace a property-less mark with a link" path was simply never implemented; there is no data-loss argument for it.
Proposal
Allow switching a single touched property-less mark (strong, emphasis, code, …) to a link. Nothing is lost: marks are mutually exclusive, the source mark carries no data, and the link's href is supplied by the URL prompt. The reverse direction stays forbidden via can_switch_mark_type.
Proposed change to ToggleLinkCommand (for discussion, not yet implemented):
is_enabled() {
const { session, editable } = this.context;
const selected_marks = session.selected_marks;
const selection_touches_marks = selected_marks.length > 0;
const can_remove_link = selected_marks.length === 1 && selected_marks[0].node.type === 'link';
// A single property-less mark (e.g. strong, emphasis) may be switched to
// a link: nothing is lost, the href is supplied by the prompt.
const can_switch_to_link =
selected_marks.length === 1 &&
!can_remove_link &&
Object.keys(session.schema[selected_marks[0].node.type]?.properties ?? {}).length === 0;
const can_create_link =
!selection_touches_marks &&
session.selection?.type === 'text' &&
!is_selection_collapsed(session.selection);
return Boolean(
editable &&
session.selection?.type === 'text' &&
(can_remove_link || can_create_link || can_switch_to_link)
);
}
execute() {
const session = this.context.session;
const selected_marks = session.selected_marks;
const can_remove_link = selected_marks.length === 1 && selected_marks[0].node.type === 'link';
if (can_remove_link) {
// Delete link
session.apply(session.tr.toggle_mark('link'));
} else {
// Create link, or switch a single property-less mark to a link
const href = window.prompt('Enter the URL', 'https://example.com');
if (href) {
session.apply(session.tr.toggle_mark('link', { href }));
}
}
}
Open questions
- Does
tr.toggle_mark('link', { href })correctly displace the touched property-less mark in the switch case? The generic switch path inToggleMarkCommandcalls it without properties — needs verification plus a test. - Behavior for partially touched marks: should switching require the selection to cover the mark, or is touch enough (current
ToggleMarkCommandswitch semantics)? - Should this generalize? Any future data-carrying mark command (e.g. a comment mark) would want the same pattern: switching to it is fine when the source is property-less and the target's properties are collected in its own UI. Could be a shared helper, e.g.
can_switch_to_mark_type(schema, from_type)as the source-side half ofcan_switch_mark_type.
- Dominant language
- TypeScript
- Stars
- 691
- Forks
- 20
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from michael/svedit
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Similar issues
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/clickhouse-js#1293 ·
Maintainers usually reply within 1 day
-
area: middleware enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
agent/quality testing
Difficulty 1/5 Under an hour Newbie friendliness 95/100
Maintainers usually reply within 1 day
-
GitHub registry install via `gh` credentials rewrites `\u0000`–`\u001f` escapes in source files to `^@`–`^_`Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
juspay/agent-distro#203 ·
Maintainers usually reply within 1 day