Processing pasted tabs

I have ‘Indent Unit’ set to 4 in Inkdrop and TAB is entered as Space x 4.

However, when I copy and paste a code snippet from another editor, the tab does not expand into a space, but remains \t, which is Space x 2.

I have to readjust the indentation in Inkdrop every time.

I think it would be appropriate if pasted tabs were also rendered according to the ‘Indent Unit’.

Info

  • Platform: (Windows)
  • Platform version: (10)
  • App Version: (5.3.1)

Reproduce

Copy and paste code or documents that contain tabs.

Hey Avis,

Let me answer after the paternity break!

Congratulations on that!
I’m not in a hurry, so it’s okay.

CodeMirror has an option tabSize: https://codemirror.net/doc/manual.html#option_tabSize
So, it’d be nice to support it instead of converting tabs into spaces.

Thank you for your answer.
Do you have any plans to support this in inkdrop?

I’m currently working on the mobile app.
You can specify it with init.js like so:

inkdrop.onEditorLoad(() => {
  var cm = inkdrop.getActiveEditorOrThrowError().cm
  cm.setOption('tabSize', 2)
})

Thanks, that was very helpful.
I am now able to adjust the CodeMirror settings.

I no longer need to rework the snippet after I put it up.

However, it doesn’t match the settings in Inkdrop, so hopefully this will be improved someday.

1 Like

Yes, it’ll be supported in the next release!

1 Like

It’s now supported in v5.4.0:tada:

1 Like

I’m still noticing, when pasting from other sources that have tab-indented text (like Logseq and some other outliners), I get messed-up indentation in Inkdrop.

Is there something I can do inside Inkdrop to handle pasting of these tab-indented sources, or do I have to manually switch out tabs for double spaces before pasting? My current tab size/indent unit is 4, but switching that out to 2 doesn’t make a difference.

Logseq, Sublime, Inkdrop (in order):

@J_N
Inkdrop does not convert tabs into spaces when pasting.
Do you mean changing the tab size does not work?
Why does the second line start with - - and why does the line “A” not have a dash? How do you paste it?

I don’t know :sweat_smile:

This is the behaviour I’m seeing, and it seems to vary with apps I’m pasting from. There seems to be a difference between ⌘C + ⌘V pasting and Pasting as plain text ⌥⇧⌘V.

  1. TextEdit/Sublime
- Point A
	- Subpoint A
		- Sub-subpoint A
- Point B
	- Subpoint B
		- Sub-subpoint B

Nothing fancy, just tab-indented text, ends up in Inkdrop like this:

There’s some kind of invisible indentation happening because a) the syntax colour is different for every line, and b) the dashes aren’t perfectly aligned. Preview seems to render correctly.

  1. Logseq
    If I do Paste as plain text ⌥⇧⌘V, I end up with the same result, but if I simply do ⌘C + ⌘V, then I end up with this:

However, this is where things get weird, if I ⌘C + ⌘V just Point A and its children, I get this:

All the dashes you see here are indented by 2 spaces, even though my settings in Inkdrop are Indent unit:4 and Tab size: 4.

Bottom line is, no matter what I do, I can’t seem to get tab-indented text into Inkdrop correctly. I’m guessing for now, manually changing tabs to spaces is the only option?

@J_N, thanks for the detailed explanation.
The corrupt indent is due to a feature to align items to the bullets like this:

But it doesn’t work well with tab-indented lists.

Regarding pasting from Logseq, it copies the list as plain text and HTML. When pressing ⌘V, it tries to convert the HTML into Markdown but the HTML structure is not identical to the original list structure. So, that’s why it only works properly with ⌥⇧⌘V, which pastes plain text from the clipboard.

Unfortunately, the library for converting HTML to MD does not support specifying the indent size.

Yeah, I think the app should convert tab indentations to spaces when pasting plain text.
Thanks again for the feedback!

@J_N Can you please try this patch? https://d3ip0rje8grhnl.cloudfront.net/v5.11.4/Inkdrop-5.11.4-arm64-Mac.zip
When pasting multiline plain text, it should replace tabs with spaces. It respects the tab size config.

I’ve given this a spin, here’s what I find:

  1. Plain text
    • Tabs convert correctly to whatever config I have set for indentation (I’ve tried changing from 4 to 2 and back again, and it looks like it works), so this is good.
  2. HTML
    • still uses 2 spaces, so consistent behaviour with what you’ve explained about HTML → MD.
  3. Rich text
    • Still getting double dashes when pasting from rich text, i.e. from Apple Notes (see below).
    • If I paste rich text with ⌥⇧⌘V, I’ll get varied results depending on source application, but I guess that’s a different issue.

Apple Notes, rich text:

The main takeaway is that tab-indented plain text now seems to transfer correctly, which is a win :slight_smile:

1 Like

@J_N Thanks for checking it out!
Yes, you are correct. Seems like Apple Notes has the same issue with Logseq.
You copy HTML like this:

<ul class="ul1">
   <li class="li1"><span class="s1"></span>what about notes</li>
   <ul class="ul1">
      <li class="li1"><span class="s1"></span>how does formatting look <b>here</b></li>
   </ul>
   <li class="li1"><span class="s1"></span>does it copy <a href="https://www.inkdrop.app/">links</a>?</li>
   <ul class="ul1">
      <li class="li1"><span class="s2"></span><i>italics</i>?</li>
   </ul>
</ul>

The child ul is directly under the parent ul, which is actually incorrect and not supported by the converter library.

Well, I guess it’s good to roll this patch out. Thanks again!

1 Like

Landed in v5.11.4 :raised_hands: Thanks again for your feedback!