uiwjs / uiwjs/react-md-editor

Selection strategy for list commands

Open
#588 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2.9k
Forks
201
Avg merge
12m
Merged PRs (30d)
1

Description

Hi!

I would like list commands (unordered list, ordered list and checked list commands) to be applied to the whole line instead of word.
For now, I've achieved that by defining custom commands and overriding the makeList() function:

import { checkedListCommand, orderedListCommand, unorderedListCommand} from '@uiw/react-md-editor';

const makeList = (state: ExecuteState, api: TextAreaTextApi, insertBefore: string | AlterLineFunction): void => {
    // const newSelectionRange = selectWord({ text: state.text, selection: state.selection, prefix: state.command.prefix! });
    const newSelectionRange = selectLine({
        text: state.text,
        selection: state.selection
    });
    
    // ... 
    // copy/paste all the remaining code from source
    // ...
};

export const customUnorderedListCommand: ICommand = {
    ...unorderedListCommand,
    execute: (state: ExecuteState, api: TextAreaTextApi) => {
        makeList(state, api, '- ');
    }
};

export const customOrderedListCommand: ICommand = {
    ...orderedListCommand,
    execute: (state: ExecuteState, api: TextAreaTextApi) => {
        makeList(state, api, (item, index) => `${index + 1}. `);
    }
};

export const customCheckedListCommand: ICommand = {
    ...checkedListCommand,
    execute: (state: ExecuteState, api: TextAreaTextApi) => {
        makeList(state, api, () => `- [ ] `);
    }
};

Would it be possible to have something like a selectionStrategy option on the commands, that could be set to word or line for example? Then the makeList() function would use selectWord() or selectLine() accordingly?

Thanks for you great work!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the list command entry points, makeList(), selectWord(), and selectLine() referenced in the issue. Check how unorderedListCommand, orderedListCommand, and checkedListCommand are defined and how command options are typed. Done means the commands can choose word or line selection through a selectionStrategy option without custom command overrides.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.