qmk_firmware/assets/features_autocorrect.md.BgqtSxc-.js

16 lines
58 KiB
JavaScript
Raw Normal View History

import { _ as _export_sfc, c as createElementBlock, o as openBlock, a8 as createStaticVNode } from "./chunks/framework.B9AX-CPi.js";
const __pageData = JSON.parse('{"title":"Autocorrect","description":"","frontmatter":{},"headers":[],"relativePath":"features/autocorrect.md","filePath":"features/autocorrect.md"}');
const _sfc_main = { name: "features/autocorrect.md" };
const _hoisted_1 = /* @__PURE__ */ createStaticVNode('<h1 id="autocorrect" tabindex="-1">Autocorrect <a class="header-anchor" href="#autocorrect" aria-label="Permalink to &quot;Autocorrect&quot;"></a></h1><p>There are a lot of words that are prone to being typed incorrectly, due to habit, sequence or just user error. This feature leverages your firmware to automatically correct these errors, to help reduce typos.</p><h2 id="how-does-it-work" tabindex="-1">How does it work? <a class="header-anchor" href="#how-does-it-work" aria-label="Permalink to &quot;How does it work? {#how-does-it-work}&quot;"></a></h2><p>The feature maintains a small buffer of recent key presses. On each key press, it checks whether the buffer ends in a recognized typo, and if so, automatically sends keystrokes to correct it.</p><p>The tricky part is how to efficiently check the buffer for typos. We dont want to spend too much memory or time on storing or searching the typos. A good solution is to represent the typos with a trie data structure. A trie is a tree data structure where each node is a letter, and words are formed by following a path to one of the leaves.</p><p><img src="https://i.imgur.com/HL5DP8H.png" alt="An example trie"></p><p>Since we search whether the buffer ends in a typo, we store the trie writing in reverse. The trie is queried starting from the last letter, then second to last letter, and so on, until either a letter doesnt match or we reach a leaf, meaning a typo was found.</p><h2 id="how-do-i-enable-autocorrection" tabindex="-1">How do I enable Autocorrection <a class="header-anchor" href="#how-do-i-enable-autocorrection" aria-label="Permalink to &quot;How do I enable Autocorrection {#how-do-i-enable-autocorrection}&quot;"></a></h2><p>In your <code>rules.mk</code>, add this:</p><div class="language-make vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">make</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">AUTOCORRECT_ENABLE = yes</span></span></code></pre></div><p>Additionally, you will need a library for autocorrection. A small sample library is included by default, so that you can get up and running right away, but you can provide a customized library.</p><p>By default, autocorrect is disabled. To enable it, you need to use the <code>AC_TOGG</code> keycode to enable it. The status is stored in persistent memory, so you shouldn&#39;t need to enabled it again.</p><h2 id="customizing-autocorrect-library" tabindex="-1">Customizing autocorrect library <a class="header-anchor" href="#customizing-autocorrect-library" aria-label="Permalink to &quot;Customizing autocorrect library {#customizing-autocorrect-library}&quot;"></a></h2><p>To provide a custom library, you need to create a text file with the corrections. For instance:</p><div class="language-text vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">text</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span>:thier -&gt; their</span></span>\n<span class="line"><span>fitler -&gt; filter</span></span>\n<span class="line"><span>lenght -&gt; length</span></span>\n<span class="line"><span>ouput -&gt; output</span></span>\n<span class="line"><span>widht -&gt; width</span></span></code></pre></div><p>The syntax is <code>typo -&gt; correction</code>. Typos and corrections are case insensitive, and any whitespace before or after the typo and correction is ignored. The typo must be only the letters az, or the special character : representing a word break. The correction may have any non-unicode characters.</p><p>Then, run:</p><div class="language-sh vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">qmk</span><span style
const _hoisted_79 = [
_hoisted_1
];
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createElementBlock("div", null, _hoisted_79);
}
const autocorrect = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export {
__pageData,
autocorrect as default
};