-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
fix: sceneCoordsToViewportCoords, jumping text when there is an offset (#4413) #4630
Conversation
Text edit events
Zoom to fit api
On drop event
fixed zoom to max when empty, and target null
Update App.tsx
Co-authored-by: Aakansha Doshi <aakansha1216@gmail.com>
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/excalidraw/excalidraw/6waJcPj6ZB2JBKkSx23s8kSY2EMG |
@ad1992, this simplifies and resolves the errors (and heuristic "magic") with text positioning in textwysiwyg. This change greatly improves the user experience for Excalidraw when it is rendered embedded in an app with offsetLeft & offsetTop !=0. Please take a look and let's push this important improvement to production. |
Number( | ||
getComputedStyle( | ||
excalidrawContainer?.parentNode as Element, | ||
).marginRight.slice(0, -2), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note sure about what this solved before, but shouldn't w keep this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this deliberately and after extensive testing. I think it is based on the misunderstanding that appState.width is the entire screen width, while in reality, it is the canvasDOMWidth. Subtracting the right-hand side margin is unnecessary.
excalidraw/src/components/App.tsx
Lines 380 to 395 in c009e03
const { | |
width: canvasDOMWidth, | |
height: canvasDOMHeight, | |
viewModeEnabled, | |
} = this.state; | |
const canvasWidth = canvasDOMWidth * canvasScale; | |
const canvasHeight = canvasDOMHeight * canvasScale; | |
if (viewModeEnabled) { | |
return ( | |
<canvas | |
className="excalidraw__canvas" | |
style={{ | |
width: canvasDOMWidth, | |
height: canvasDOMHeight, | |
cursor: CURSOR_TYPE.GRAB, | |
}} |
This is a great improvement @zsviczian ❤️. Could you also write specs for this ? Will do one round of testing and then should be good to merge. |
Great! A second (and 3rd, 4th...) round of testing is always essential. What do you mean by specs? |
I meant tests for the change just to make sure we don't break in future as this part has been broken often in the past. |
I think this broke frequently in the future because there was a formula error. sceneCoordsToViewportCoords was wrong, and we were trying to resolve its impact by applying complex calculations in textwysiwyg. That should be resolved for good. Regarding testing... I don't really know how to test for zoom and offset situations... I haven't yet looked at excalidraw tests, I'll take a look to see if this sort of testing can be automated. My recommendation would be to deploy a second app with every change, the second should have offsets and righthand side margin. |
Sure 👍🏻 . The tests would probably be tricky for this but lets give it a try and decide accordingly :).
What do you mean by deploying an app with offsets and right handed margin ? We have the same code sandbox example running with package example in port 3001 which can be used for testing |
To make the question concrete. If I would want to test a PR with screen offsets, how can I do that. For sake of example, the current preview release for the hyperlinks PR is https://excalidraw-f13roaq8h-excalidraw.vercel.app/ I tried https://excalidraw-f13roaq8h-excalidraw.vercel.app:3001/ but that did not bring up anything... |
Ohh ok I meant it will work in |
That would be great! I was looking around the repository but didn't yet have the patience to figure it out. If you give me some pointers I am also happy to propose a PR with port 3001 being available in preview too. BTW Have you had time to test this fix? I've deployed this to the Obsidian Excalidraw build a week ago and have not experienced any issues since. I am pretty confident that this is working as expected. Would be good to get this deployed before further functions build on the current erroneous sceneCoordsToViewportCoords() function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 from my side, tested it out and it works great, thanks @zsviczian for fixing this 💯 , lets wait for @dwelle's +1 as well and then we are good to 🚀
For sure, let's merge! Thanks! |
This resolves #4413 and fixes the incorrect sceneCoordsToViewportCoords function.
Before
old.mp4
After
new.mp4