Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide markdown syntaxes like Typora does #1133

Open
yy0931 opened this issue Jun 19, 2022 · 2 comments
Open

Hide markdown syntaxes like Typora does #1133

yy0931 opened this issue Jun 19, 2022 · 2 comments
Labels
Area: Editor theming Decorations and highlighting in editor. Issue: Epic Mega thread (plan) which may involve features, bugs, and tasks. Issue: Feature Something brand new.

Comments

@yy0931
Copy link
Contributor

yy0931 commented Jun 19, 2022

Proposal

Take a look at this prototype. I did not know that VSCode could hide characters until I found vscode-inline-fold extension.
There is already markdown.extension.syntax.plainTheme configuration (#185) that serves the same purpose but this is much better. This feature should be especially useful when you have links with long URLs. (edit: There is a problem with line breaks being done in the original number of characters (see 1 and the upstream issue) so it may not be suitable for links for now.)

markdown

Source code:

import vscode from "vscode"

export const activate = (context: vscode.ExtensionContext) => {
    const decorationType = vscode.window.createTextEditorDecorationType({ textDecoration: "none; display: none;" })

    const updateDecorations = () => {
        const editor = vscode.window.activeTextEditor
        if (editor === undefined) { return }
        if (editor.document.languageId !== "markdown") {
            editor.setDecorations(decorationType, [])
            return
        }

        const selectedLines = new Set<number>()
        for (const sel of editor.selections) {
            for (let i = sel.start.line; i <= sel.end.line; i++) {
                selectedLines.add(i)
            }
        }

        const ranges: vscode.Range[] = []
        for (let i = 0; i < editor.document.lineCount; i++) {
            if (selectedLines.has(i)) { continue }
            const line = editor.document.lineAt(i)
            for (const match of line.text.matchAll(/(?<!\\)\*|\([^)]*\)|\[|\]/g)) {  // FIXME: Use a markdown parser
                ranges.push(new vscode.Range(line.range.start.line, match.index!, line.range.end.line, match.index! + match[0].length))
            }
        }
        editor.setDecorations(decorationType, ranges)
    }

    updateDecorations()
    context.subscriptions.push(
        vscode.window.onDidChangeActiveTextEditor(() => { updateDecorations() }),
        vscode.workspace.onDidChangeTextDocument(() => { updateDecorations() }),
        vscode.window.onDidChangeTextEditorSelection(() => { updateDecorations() })
    )
}

export const deactivate = () => { }

References

#929

Footnotes

  1. problem

@yy0931
Copy link
Contributor Author

yy0931 commented Jun 20, 2022

If you like it I can work on a PR.

@yzhang-gh
Copy link
Owner

This is quite interesting.

PRs are always welcome. At least we can make it an experimental feature if it is not stable enough.

@yzhang-gh yzhang-gh added Issue: Feature Something brand new. Area: Editor theming Decorations and highlighting in editor. Issue: Epic Mega thread (plan) which may involve features, bugs, and tasks. labels Jun 20, 2022
@yy0931 yy0931 mentioned this issue Jun 20, 2022
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Editor theming Decorations and highlighting in editor. Issue: Epic Mega thread (plan) which may involve features, bugs, and tasks. Issue: Feature Something brand new.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants