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

refactor(): canvas text editing manager #8543

Merged
merged 42 commits into from
Jan 12, 2023
Merged

refactor(): canvas text editing manager #8543

merged 42 commits into from
Jan 12, 2023

Conversation

ShaMan123
Copy link
Contributor

@ShaMan123 ShaMan123 commented Dec 29, 2022

Motivation

Another step making text classes readable, simpler, Scoped which they are absolutely not

Description

extracted the logic that handles canvas itext instances from itext_behavior to a dedicated manager

Changes

  • register itext from _set. This will handle cases such as nested itexts.
  • delegate mouse move invocation to the manager

Gist

In Action

Copy link
Contributor Author

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Progress

src/mixins/itext_behavior.mixin.ts Show resolved Hide resolved
@@ -94,7 +94,7 @@ export class Text<
* @type Array
* @private
*/
_dimensionAffectingProps: (keyof this)[];
_dimensionAffectingProps: string[];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TS went mad because of this line


add(target: IText | Textbox) {
if (!this.disposer) {
const disposer = this.canvas.on('mouse:up', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try to remove the need for the subscription

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@github-actions
Copy link
Contributor

github-actions bot commented Dec 29, 2022

Build Stats

file / KB (diff) bundled minified
fabric 927.379 (-0.987) 298.827 (-0.283)

@github-actions
Copy link
Contributor

github-actions bot commented Dec 29, 2022

Coverage after merging itext-canvas-handler into master will be

83.19%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
index.ts100%100%100%100%
src
   cache.ts96.97%90%100%100%56
   config.ts77.27%66.67%66.67%84.62%130, 138–140, 151–153
   constants.ts100%100%100%100%
   env.ts72.73%53.33%100%79.17%22, 22–23, 23, 23, 25, 25, 27, 29, 31–32, 62
   intersection.class.ts100%100%100%100%
   pattern.class.ts92.19%85.71%100%96.30%118, 124, 135, 144, 96
   point.class.ts100%100%100%100%
   shadow.class.ts98.48%96%100%100%156
   typedefs.ts100%100%100%100%
src/brushes
   base_brush.class.ts100%100%100%100%
   circle_brush.class.ts0%0%0%0%100, 102–104, 113, 113, 113, 115, 117, 119–121, 123–126, 134, 141, 143, 23, 28–29, 37–41, 45–49, 56–59, 67–71, 73, 81, 81, 81, 81, 81–82, 84, 84, 84–87, 89, 97–98
   pattern_brush.class.ts97.06%87.50%100%100%21
   pencil_brush.class.ts91.86%85.42%100%93.58%122–123, 152, 152–154, 276, 280, 285–286, 68–69, 84–85
   spray_brush.class.ts0%0%0%0%100–101, 103–104, 112, 112, 112, 112, 112–113, 115–116, 123–124, 126, 128–132, 141, 145–146, 146, 154, 154, 154–157, 159–162, 166–167, 169, 171–174, 177, 184–185, 187, 189–190, 192, 199–200, 202–203, 206, 206, 213, 213, 217, 22–23, 25–27, 27, 27–29, 33, 42, 49, 56, 63, 70, 77, 89–91, 99
src/canvas
   TextEditingManager.ts100%100%100%100%
   canvas.class.ts93.07%89.06%94%95.87%1151, 1151–1152, 1155, 1175, 1175, 1237, 1273–1274, 1293–1294, 1302–1303, 1324, 1332, 1445–1446, 1448–1449, 1469–1470, 507, 574–575, 580, 590, 719–720, 722–723, 723, 723, 769–770, 831–832, 885–887, 917, 922–923, 952–953
   canvas_events.ts78.34%75.69%82.35%79.49%1005–1006, 1006, 1006–1008, 1010–1011, 1011, 1011, 1013, 1021, 1021, 1021–1023, 1023, 1023, 1029–1030, 1038–1039, 1039, 1039–1040, 1045, 1047, 1077–1079, 1082–1083, 1087–1088, 1204–1206, 1209–1210, 1283, 1403, 147, 1497–1498, 1504, 1508–1509, 1525, 1547, 1594, 1599, 1638, 1647, 172, 320–321, 321, 321–322, 322, 325–329, 334, 336, 349–352, 355, 374, 374, 374–375, 375, 375–376, 384, 389–390, 390, 390–391, 393, 402, 408–409, 409, 409, 445, 449, 449, 449, 449, 449–450, 452, 527, 529, 529, 529–531, 551, 553, 553, 553–554, 554, 554, 557, 557, 557–558, 561, 570–571, 573–574, 576, 576–577, 579–580, 592–593, 593, 593–594, 596–600, 606, 613, 653, 653, 653, 655, 657–661, 667, 673, 673, 673–674, 676, 679, 684, 697, 724, 780–781, 781, 781–782, 784, 787–788, 788, 788–789, 791–792, 795, 795–797, 800–801, 811, 893, 907, 914, 935, 967, 988–989
   static_canvas.class.ts94.67%89.27%97.92%97.10%1118–1119, 1119, 1119–1120, 1240, 1250, 1304–1305, 1308, 1343–1344, 1422, 1431, 1436, 1485–1486, 1714, 1714–1715, 1764, 1767, 1770, 1770, 1770, 1773, 1776, 1776, 1776, 338, 351, 404–405, 407–408, 417, 421–422, 425–426, 878
src/color
   color.class.ts92.20%86.49%100%94.34%330–331, 335–336, 339–340, 58, 88–89, 89, 91, 91, 91–92, 94–95
   color_map.ts100%100%100%100%
   constants.ts100%100%100%100%
   util.ts100%100%100%100%
src/controls
   changeWidth.ts100%100%100%100%
   control.class.ts93.98%88.89%90.91%97.78%235, 319, 319, 354
   controls.render.ts81.63%78%100%84.78%106, 111, 121, 121, 45, 50, 61, 61, 65–72, 81–82
   default_controls.ts86.67%66.67%100%100%122, 129
   drag.ts100%100%100%100%
   polyControl.ts6.35%0%0%11.43%100, 105, 119, 121–124, 124, 127, 134, 17, 25–28, 30, 30, 30, 30, 30, 30, 30, 30, 50–56, 56, 56, 56, 56, 58, 63–64, 66, 76, 82–83, 83, 83–84, 88–90, 90, 90, 90, 90, 92
   rotate.ts20%12.50%50%22.22%45, 51, 51, 51–52, 55–57, 59, 59, 59, 59, 59–61, 61, 61–63, 65, 65, 65–67, 67, 67–68, 73, 73, 73–74, 76, 78, 80–81
   scale.ts93.41%92.68%100%93.59%129–130, 132–134, 148–149, 181–183, 42
   scaleSkew.ts78.79%64.29%100%85.71%27, 29, 29, 29, 31, 33, 35
   skew.ts91.03%79.31%100%97.67%130–131, 162–163, 170, 176, 178
   util.ts100%100%100%100%
   wrapWithFireEvent.ts100%100%100%100%
   wrapWithFixedAnchor.ts100%100%100%100%
src/filters
   2d_backend.class.ts92%83.33%100%93.75%35–36
   FilterBackend.ts88.89%88.89%100%85.71%15–16
   WebGLProbe.ts37.14%40%60%30%28–30, 30,

@ShaMan123 ShaMan123 changed the title chore(TS): canvas text editing manager refactor(): canvas text editing manager Dec 29, 2022
I think this should not be an issue
tests fail because IText is used on StaticCanvas and shouldn't  really
@ShaMan123 ShaMan123 requested a review from asturur December 29, 2022 11:48
Copy link
Contributor Author

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems ready
tested live as well

Copy link
Contributor Author

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated from master

Copy link
Contributor Author

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extensive test

@ShaMan123 ShaMan123 added the text label Jan 10, 2023
Copy link
Contributor Author

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why the mouse move handler (now renamed to updateSelection) is not called from the object's mousemove event. so moving outside the textbox will still update selection.

  • It seems selected is handled by mouse up so no need to false it from the manager
  • rm __isMousedown:
    • used for updating selection only when mouse move after mouse down (now handled by the manager)
    • used to render the cursor with global alpha = 1, fixed to not run cursor animation in such a case

This PR is becoming less scoped and is about to clash with #8583 #8534

A few fixes so tests pass and I am done hopefully

@@ -521,7 +434,6 @@ export abstract class ITextBehaviorMixin<
this.selectionStart !== currentStart ||
this.selectionEnd !== currentEnd
) {
this.restartCursorIfNeeded();
Copy link
Contributor Author

@ShaMan123 ShaMan123 Jan 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

important fix
no reason to do this here, in case of a cursor the animation will be started from mouse up

src/mixins/itext_behavior.mixin.ts Outdated Show resolved Hide resolved
// avoid running this logic when there is an active object
// this because is possible with shift click and fast clicks,
// to rapidly deselect and reselect this object and trigger an enterEdit
return;
}

if (this.__lastSelected && !this.__corner) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this bit is really harsh, hard to understand logic

Copy link
Contributor Author

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

READY

@asturur
Copy link
Member

asturur commented Jan 10, 2023

I think this all in all is better than what we had before, is also a change that will open up to regressions for sure.
If you can do that rename and remove the !this.selected then we can merge

@asturur
Copy link
Member

asturur commented Jan 10, 2023

Oh also please tell me more about those nexted Itexts
Are you talking about adding a group that has an itext inside?

Copy link
Contributor Author

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applied changes from review

@ShaMan123 ShaMan123 requested a review from asturur January 11, 2023 07:06
@asturur
Copy link
Member

asturur commented Jan 12, 2023

This is good work imho, just not convinced about that _set usage.
Would really leave set to small things.
I m sure later we can find a way to use onObject added for that.
I don't see an issue with onObjectAdded traversing the objects.
Something is setting canvas prop on every object in a group when we move a group from a canvas to another, so this mechanism already exists somewhere

@asturur asturur merged commit 8b102b7 into master Jan 12, 2023
@asturur asturur deleted the itext-canvas-handler branch January 12, 2023 00:54
@ShaMan123
Copy link
Contributor Author

Very good point
We can move away from set

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants