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

💡Indent inline text on tab key pressed #1163

Open
yoonwaiyan opened this issue May 23, 2020 · 8 comments
Open

💡Indent inline text on tab key pressed #1163

yoonwaiyan opened this issue May 23, 2020 · 8 comments

Comments

@yoonwaiyan
Copy link

  1. Describe a problem.
    When I press the tab key in a new line, it shows a toolbar but I'd like the text to indent as a nested block.

  2. Describe the solution you'd like. Mockups are welcome.
    It's handy to make the inline text to indent after the tab key is pressed - this behavior can be seen in both Notion and Roam Research. Maybe make key shortcuts configurable to render customized actions?

  3. Are there any alternatives?
    Or make it as an Inline Tool? But as a markdown user I'd prefer to have quick typing without too many keystrokes for styling.

@flaming-cl
Copy link
Contributor

flaming-cl commented May 23, 2020

Hi, this might be a solution for your problem:

turn off the editor tab event

You may need to modify the original editor.js code library.

  1. add a config to disable the editor/browser tab event
    editing INTERNAL_SETTINGS at editor.js/src/components/modules/tools.ts
 public get INTERNAL_SETTINGS(): {[name: string]: string} {
    return {
      IS_ENABLED_LINE_BREAKS: 'enableLineBreaks',
      IS_DISABLED_DEFAULT_TAB_EVENT: 'disableDefaultTabEvent', // the new config
      IS_INLINE: 'isInline',
      TITLE: 'title', 
      SHORTCUT: 'shortcut',
      TOOLBOX: 'toolbox',
      SANITIZE_CONFIG: 'sanitize',
      CONVERSION_CONFIG: 'conversionConfig',
    };
  }
  1. edit the tabPressed event at editor.js/src/components/modules/blockEvents.ts
    if (tool && tool[Tools.INTERNAL_SETTINGS.IS_DISABLED_DEFAULT_TAB_EVENT]) {
      event.preventDefault();
      return;
    }
  1. build the editor.js project, replace the editor.js file in your own project

editing in your own project

  1. set disableDefaultTabEvent to be true in your tool class (this can be a Paragraph plugin)
  static get disableDefaultTabEvent() {
    return true;
  }
  1. set up your own tab event in the tool class
    edit the onKeyUp event
if (e.code === 'Tab') {
      this.yourIndentInsertFunction()
}

@yoonwaiyan
Copy link
Author

Thanks for your suggestion! I'm wondering is this possible to make it as a feature to eliminate my need to permanently maintaining my own fork.

@flaming-cl
Copy link
Contributor

flaming-cl commented May 24, 2020

Thanks for your suggestion! I'm wondering is this possible to make it as a feature to eliminate my need to permanently maintaining my own fork.

Tab indent might be a bit troublesome in a contentEditable div. I tried my own indentInsertFunction. It works well in Chrome but failed in Safari. After inserting indents, the caret is automatically jumping to the end of the block. I did not figure out why this happened. Hope someone could make Tab indent as a feature as well.

@tommiv
Copy link

tommiv commented Aug 25, 2020

Actually the same problem present when you try to tab a textarea. I've added a custom code block plugin to my application and found it impossible to use tab in it – the keypresses are just hijacked by the editor.js engine.

@christoph-kluge
Copy link

I've found this issue #927 which seems to relevant to this issue as well. There is a small code-snippet where I have deactivated the editor.js TAB functionality and use it only while a toolbox is open.

Maybe this can help to catch the tab-event in your custom module. Code reference is here: christoph-kluge@405cd85)

@tommiv
Copy link

tommiv commented Oct 2, 2020

Thank you @christoph-kluge, I have seen this ticket. However, this workaround assumes that I maintain my own copy/fork of editor.js just to apply this patch. I'm afraid this is far from a scalable solution because at least it would be my responsibilty to keep my copy/fork up to date. It would be much better if the option provided by the library itself.

@christoph-kluge
Copy link

@tommiv I see. Just wanted to give you an heads up how to achieve it.

In my case I do only update the library every now and then when there is something relevant for me in a new release. In this case my personal effort is fine and I'm trying to add support for my own relevant features.

@evanjmg
Copy link

evanjmg commented May 17, 2022

solution above works but backspacing is problematic - the block prior just disappears

@neSpecc neSpecc removed the feature label Jan 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants