Insert TAB character in text without doing tab indenting

I use TAB characters in text to align columns. Unfortunately, hitting TAB indents the block. I’ve tried to use remapping functions, but the only way I can currently insert a TAB character is to copy and paste it. Is there a way to remap something like CTRL-TAB (just making this up) to do what I want? Thanks.

Welcome. For CTRL-TAB to simply insert a TAB character, try putting the following code inside file custom.js (create in folder logseq if it doesn’t already exist), then restart Logseq and accept the warning:

document.addEventListener("keyup", (e)=>{
    if (e.code === "Tab" && e.ctrlKey) {
        const ta = document.querySelector("textarea")
        const text = ta.value
        ta.value = text.slice(0, ta.selectionStart) + "\t" + text.slice(ta.selectionEnd)
    }
});
2 Likes

I put the suggested code in the main directory’s Logseq subdirectory and the two graph’s Logseq directory. It did request permission to run once, but CTRL-TAB either does nothing -or- causes the block to lose focus.

I have updated the code in my answer. Please try again.

1 Like

I tried the latest version. It works, with a minor issue. The first time after bring up Logseq, hitting CTRL-TAB causes the block to lose focus. After that I get the expected (advertised) results of inserting a TAB character where the cursor is. I can live with this, no problem. I just thought you should know.

  • This has never happened to me, no matter the restarts.
  • Have you cleaned up your previous remapping efforts?
  • You may want to try with a different key combination.

I had 3 copies of your code in custom.js, one under the main logseq directory, and two under separate graphs. Inasmuch as this happens (losing focus on the block) only once per restart of Logseq, I’m not going to worry about it. I am using the current Windows version 0.10.9. I wish to thank you for your assistance in this matter, and following up on my original request and the issues with the original code. You saved me from having to copy/ paste TABs, and that’s what I wanted. Thank you. – Phil