Needs work
Project:
Paragraphs
Version:
8.x-1.x-dev
Component:
User interface
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
28 Mar 2018 at 22:05 UTC
Updated:
9 Dec 2018 at 22:30 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
sasanikolic commentedI added the if checks for the case when the first paragraph is deleted in a new function.
Here is the patch with the working solution.
Comment #3
miro_dietikerComment #4
miro_dietikerThe helper method code amount looks like we can loop over the paragraph items and simply pick the first non-deleted one at the same complexity.
Comment #5
toncic commented+1 for to make this more dynamic, to do not depend only on first 2 items.
Also we should try to find better name for this function. Something like 'getViewMode' or similar.
Comment #6
sasanikolic commentedHi @miro_dietiker, I implemented your and @toncic's feedback in this patch.
Comment #7
sasanikolic commentedComment #8
miro_dietikerThe term "View mode" has a clear meaning and is a different thing. That's why we name the key "edit_mode". Let's stick to that.
Also it is not returning a generic "edit mode". Each delta has its own edit mode. The method only determines the edit mode of the first delta by considering the default. We should name the interface accodringly.
Comment #9
sasanikolic commentedI agree with the naming. Here is the patch with the improved naming and updated interface and comments.
Comment #10
miro_dietikerComment #11
miro_dietikerSorry for another round: To better support reuse we maybe should transform the method to "getFirstVisibleItemState" that just skips removed items, returning the item state as a whole.
The caller can then again apply the ternary.
I couldn't find any other occurence of ['paragraphs'][0] in Paragraphs itself anymore, but it's a common problem if you add other conditional actions. Maybe i have missed something...
I will also ping Berdir for quick feedback here to decide.
Comment #12
berdirA bit strange that we check for delta 0 in the condition but then loop over it, should be enough to just check that 'paragraphs' is defined?
Also, you can simplify it by just doing a return instead of setting a variable and doing a break.
Not sure if it's worth doing the suggested refactoring, I don't think it's such a common use case.