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

Auto-convert on typing #16

Open
waldyrious opened this issue Dec 12, 2022 · 2 comments
Open

Auto-convert on typing #16

waldyrious opened this issue Dec 12, 2022 · 2 comments
Labels
hacktoberfest Issues that welcome PRs from Hacktoberfest participants ready Issues with sufficient context and direction (and no blockers) that can be tackled right away. UI/UX Changes that affect the design or user experience of the project.

Comments

@waldyrious
Copy link
Owner

waldyrious commented Dec 12, 2022

Instead of a "Run" button, we should simply convert the text automatically whenever the input changes. The experience should be similar to this (incomplete) rST converter: https://seikichi.github.io/restructured/.

One way to achieve this could be using the onsubmit attribute of the form, as was done in an early version of the code that got commented out as the remaining pieces were being set in place:

<!-- <form oninput="html_output.value=rst_input.value"> -->

Note: converting the text automatically would probably require some sort of throttle to prevent running the conversion on every keystroke.

waldyrious added a commit that referenced this issue Dec 17, 2022
- Remove comments now tracked by an issue in the repository
  (#5
  and #16)
- Move comments out of the template literal string with Python code
  and into the JavaScript code around it
- Expand comments to offer more context
waldyrious added a commit that referenced this issue Dec 17, 2022
- Remove comments now tracked by issues in the repository
  (#5
  and #16)
- Move comments out of the template literal string with Python code
  and into the JavaScript code around it
- Expand comments to offer more context
@waldyrious
Copy link
Owner Author

waldyrious commented Dec 18, 2022

Here's what the Djot playground uses:

<textarea id="input" autofocus placeholder="Type some djot here..."></textarea>

(https://github.com/jgm/djot/blob/52c15583dc1982adb8a32314e99344e1464e29d0/web/playground/index.html#L43)

and:

const input = document.getElementById("input");
input.onkeyup = debounce(parse_and_render, 400);

(https://github.com/jgm/djot/blob/52c15583dc1982adb8a32314e99344e1464e29d0/web/playground/index.js#L133-L134)

and:

const debounce = (func, delay) => {
    let debounceTimer
    return function() {
        const context = this
        const args = arguments
            clearTimeout(debounceTimer)
                debounceTimer
            = setTimeout(() => func.apply(context, args), delay)
    }
}

(https://github.com/jgm/djot/blob/52c15583dc1982adb8a32314e99344e1464e29d0/web/playground/index.js#L201-L210)

@waldyrious
Copy link
Owner Author

And here's the code from Pygment's demo:

textarea.addEventListener('input', debouncedUpdate);

(https://github.com/pygments/pygments/blob/f0afb01195b5890ad7758554c23308db01a45be1/doc/_static/demo.js#L67)

and:

function debouncedUpdate() {
    if (fileInput.files.length > 0)
        return;


    if (textarea.value.length < 1000) {
        highlightShortDebounce();
    } else {
        highlightLongDebounce();
    }
}

(https://github.com/pygments/pygments/blob/f0afb01195b5890ad7758554c23308db01a45be1/doc/_static/demo.js#L55-L64)

and:

const highlightShortDebounce = debounce(highlight, 50);
const highlightLongDebounce = debounce(highlight, 500);

(https://github.com/pygments/pygments/blob/f0afb01195b5890ad7758554c23308db01a45be1/doc/_static/demo.js#L52-L53)

and:

function debounce(func, timeout) {
    let timer;
    return (...args) => {
        clearTimeout(timer);
        timer = setTimeout(() => func.apply(this, args), timeout);
    };
}

(https://github.com/pygments/pygments/blob/f0afb01195b5890ad7758554c23308db01a45be1/doc/_static/demo.js#L44-L50)

For reference, this functionality was introduced in pygments/pygments@fe3d2fc (#1999).

@waldyrious waldyrious added the ready Issues with sufficient context and direction (and no blockers) that can be tackled right away. label Dec 18, 2022
@waldyrious waldyrious added this to the MVP milestone Dec 18, 2022
@waldyrious waldyrious added the UI/UX Changes that affect the design or user experience of the project. label Dec 18, 2022
@waldyrious waldyrious pinned this issue Dec 18, 2022
@waldyrious waldyrious added the hacktoberfest Issues that welcome PRs from Hacktoberfest participants label Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Issues that welcome PRs from Hacktoberfest participants ready Issues with sufficient context and direction (and no blockers) that can be tackled right away. UI/UX Changes that affect the design or user experience of the project.
Projects
None yet
Development

No branches or pull requests

1 participant