proton
proton copied to clipboard
Adds an option to disable multiple indentations in lists
@YoX89, can you please explain what your intension is with this PR as I am not sure if I understand it correctly looking at the snapshots in the PR. Both the snapshot 1 and 2 are same. Do you intend to create a feature that allows you to disable indenting if more than 1 list item is selected or if it is being indented by more than 1 level with respect to parent? Latter one is already implemented and expected to work.
My PR is to limit indentation so it's not possible to indent any list more than the first level. So if your indentation formatting is 25 it will only ever be indented 25 as a maximum. Not 50, 75 etc.
Only one level of lists.
Is that already possible?
@YoX89, that's correct. This is the default behaviour. See the demo below that I just verified on iOS 18 simulator where I am pressing tab key multiple times at each level:
To ensure that you are getting the correct behaviour, please use ListTextProcessor.handleKeyWithModifiers and pass values accordingly, e.g. key: tab for indentation.
@YoX89, for reference, this is the code that prevents indentation beyond 1 level.
Sorry I wasn't being clear! I don't mean only one indentation compared to its parent. I don't want any indentation at all.
In your example above there are 4 levels. Each one level indented compared to its parent. I don't want any levels except for the first one.
In my snapshot it's intentionally the same picture. I have a list and when I tap tab it doesn't indent further because the highest total level allowed is one.
@YoX89, got it. thanks for clarifying. I think, this is something that can be handled even without any change in Proton. You can use EditorViewDelegate didChangeSelection function. Depending on the UI you have to change the indentation, you can add logic in didChangeSelection and check for FirstLineHeadIndent for .paragraphStyle attribute. If it is the indentation that you have, you can disable indentation or handle in any other manner. If the selection length is greater than 0, you will also get .listItem attribute that you can inspect. This is called every time the selection changes either as a result of text being typed or when user taps to change the selection. Hope that helps.
Also note, creating list at first level is done using ListCommand and additional indentations are handled by ListTextProcessor. If you are only using ListCommand, it's execute function will add/remove list level at first level only. If you have ListTextProcessor registered, probably the only change you need is to remove that.
Thank you! I'll have a look on Monday if I can solve it without any changes to Proton.
Hi! Tried it out a bit now. Without registering ListTextProcessor list markers don't work beyond the first one. But you were correct that it didn't indent further when tabbing.
Also looked at didChangeSelection, it doesn't always get triggered when you press tab for example. So I'm not sure I can make it work using only that override. Here's an example of where I tab to indent the second line but didChangeSelection is not called.