Analysis
Overview
The current text model is very complicated and not easy to use.
Task requirements
In order to provide the wanted result the following changes were made:
- Remove the HotPosKind class in order to make the text model more understandable and intuitive.
- This will reduce the text functionality with applying styles as follows: the cursor won't "have style" any more. This means that if there is no selected text and ctrl+B is applied nothing will happen.
- In order to save part of the text functionality on applying styles to the text a new feature (input styles) will be added.
- This will cause the following result: if there is no selected text in the view and ctrl+B is applied then the text inserted
after this will be bold(note that if you change the cursor position the text inserted in this position will be bold, this is the
only reduced functionality from the previous text model).
Task result
The result will be source code.
Implementation idea
- Remove the HotPosKind class and related to it funtions from the model.
- Add a new property in the TextFlow model to keep the input style.
Related
(Add links to related tasks that could be useful or helpful.)
How to demo
(Provide instructions for demonstration of the task.)
Design
- Remove the HotPosKind class from org.sophie2.base.model.text.smart package. The places where functions of this class were used are refactored only by deleting the usage of the functions (example: HotPosKind.getIndexForKind(beginIndex, prevPos.getKind()) is reduced to beginIndex).
- In TextViewFlow class add a RwProp<HotStyleDef> inputStyle to hold the current inputStyle, selected by the user.
- In TextFlowLogic: ON_APPLY_STYLE if there is no selected interval add the selected user style in the inputStyle of the current flow.
- In TextFlowLogic : fireSetText function fire the newly created event with styled text created from the styles hold in the inputStyle property.
And if the handled, the inputStyle property is set to HotStyleDef.empty().(in order to prevent typing with the old styles in the future)
- In HotPos class remove the getKind function(no longer needed).
- In HeadTextFrameView class in textLayout() property remove the setting of the caret and mark pos to the end of the last changed text interval because now the last index is also updated when inserting or removing fragments of the text.(this was needed for the undo)
- In HotTextLogic: pasteText function remove the block with setting the mark pos and caret pos again because the last position is updated.
- In ImmHotText class reduce the usage of HotPosKind class.Now the indexes of the chars begins from 0 and ends with length of the text's chars. There are no mid, after ot before poses. The styles are applied from the beginning of the given interval inclusive to the end of this interval exclusive. insertChar function's body is removed and now this function uses replaceText function.
- ImmHotText:getStyleValue(HotPos,Attr) now uses getStyleValue(HotInterval,Attr) function.
- ImmHotText:changePosKind function is removed.(no longer needed)
- In ImmHotText:ElemeOp:InsertOp:updatePastIndex the index that is >= from the InsertOp's position should be updated(the logic is that you insert before the given index so the given index also should be updated)(this is really a mystery to me how the previos text has updated only the indexes that were > from the position...sholud have had troubles...so maybe some ugly dirty fix is inserted somewhere to reduce the exceptions...but I haven't managed to find it yet...)
- In ImmHotText:getIndex change the way of getting the indexes from the text. The logic is changed as follows:
- if the uid of the pos is grater than the current text id the pos index is updated with it's update future index.
- In TextFlowLogic:ON_SWITCH_STYLE if the selection interval is with equal begin and end poses set the selection interval to the previous word before the caret pos. This must be done because now we don't have style on between poses(we don't have between poses) and cannot get the style of an empty interval any more. source of the tests may be found here: [8668]
Note: some of the tests are changed because of the changed logic(the exclusion of the interval that the styles are applied to).And the last test sholud not pass yet(it's fixing is related to another ticket but is a good test so I won't remove it :)).
Implementation
- ImmHotText:replaceText function is really big and so I split it in two parts- the first function: getUnionMap returns map that is union of the given text's styles and the styles of the first char to be replaced.
- In StyleUtils:applyAttribute add an if-statement that checs if the applied attribute is in range.This is only temporary!(we don't have subMap of the
subText).
- In ImmHotText:getLastChangedInterval remove the assert because it is wrong, we create sub text with the lastChangedInterval of the parent text and we do not insert another elemOp for the subTexting, so if we have changed the paren text and make a sub text the length of the subText has no relation to the last changed parent interval.This assert is correct only if the text is not a subText of another. source of the task may be found here: [8668] [8676] [8685] [8713] [8715] [8716] [8720]
Testing
(Place the testing results here.)
Comments
(Write comments for this or later revisions here.)