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

[Editor] Ends a free highlight where the mouse pointer is (bug 1879281) #17664

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 58 additions & 7 deletions src/display/editor/outliner.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ class FreeOutliner {
// - compute the control points of the quadratic Bézier curve.
#last = new Float64Array(18);

#lastX;

#lastY;

#min;

#min_dist;
Expand Down Expand Up @@ -402,7 +406,22 @@ class FreeOutliner {
return isNaN(this.#last[8]);
}

#getLastCoords() {
const lastTop = this.#last.subarray(4, 6);
const lastBottom = this.#last.subarray(16, 18);
const [x, y, width, height] = this.#box;

return [
(this.#lastX + (lastTop[0] - lastBottom[0]) / 2 - x) / width,
(this.#lastY + (lastTop[1] - lastBottom[1]) / 2 - y) / height,
(this.#lastX + (lastBottom[0] - lastTop[0]) / 2 - x) / width,
(this.#lastY + (lastBottom[1] - lastTop[1]) / 2 - y) / height,
];
}

add({ x, y }) {
this.#lastX = x;
this.#lastY = y;
const [layerX, layerY, layerWidth, layerHeight] = this.#box;
let [x1, y1, x2, y2] = this.#last.subarray(8, 12);
const diffX = x - x2;
Expand Down Expand Up @@ -528,12 +547,14 @@ class FreeOutliner {
const lastTop = this.#last.subarray(4, 6);
const lastBottom = this.#last.subarray(16, 18);
const [x, y, width, height] = this.#box;
const [lastTopX, lastTopY, lastBottomX, lastBottomY] =
this.#getLastCoords();

if (isNaN(this.#last[6]) && !this.isEmpty()) {
// We've only two points.
return `M${(this.#last[2] - x) / width} ${
(this.#last[3] - y) / height
} L${(this.#last[4] - x) / width} ${(this.#last[5] - y) / height} L${
} L${(this.#last[4] - x) / width} ${(this.#last[5] - y) / height} L${lastTopX} ${lastTopY} L${lastBottomX} ${lastBottomY} L${
(this.#last[16] - x) / width
} ${(this.#last[17] - y) / height} L${(this.#last[14] - x) / width} ${
(this.#last[15] - y) / height
Expand All @@ -553,8 +574,9 @@ class FreeOutliner {
);
}
}

buffer.push(
`L${(lastTop[0] - x) / width} ${(lastTop[1] - y) / height} L${
`L${(lastTop[0] - x) / width} ${(lastTop[1] - y) / height} L${lastTopX} ${lastTopY} L${lastBottomX} ${lastBottomY} L${
(lastBottom[0] - x) / width
} ${(lastBottom[1] - y) / height}`
);
Expand Down Expand Up @@ -582,15 +604,19 @@ class FreeOutliner {
const lastBottom = last.subarray(16, 18);
const [layerX, layerY, layerWidth, layerHeight] = this.#box;

const points = new Float64Array(this.#points?.length ?? 0);
for (let i = 0, ii = points.length; i < ii; i += 2) {
const points = new Float64Array((this.#points?.length ?? 0) + 2);
for (let i = 0, ii = points.length - 2; i < ii; i += 2) {
points[i] = (this.#points[i] - layerX) / layerWidth;
points[i + 1] = (this.#points[i + 1] - layerY) / layerHeight;
}
points[points.length - 2] = (this.#lastX - layerX) / layerWidth;
points[points.length - 1] = (this.#lastY - layerY) / layerHeight;
const [lastTopX, lastTopY, lastBottomX, lastBottomY] =
this.#getLastCoords();

if (isNaN(last[6]) && !this.isEmpty()) {
// We've only two points.
const outline = new Float64Array(24);
const outline = new Float64Array(36);
outline.set(
[
NaN,
Expand All @@ -609,6 +635,18 @@ class FreeOutliner {
NaN,
NaN,
NaN,
lastTopX,
lastTopY,
NaN,
NaN,
NaN,
NaN,
lastBottomX,
lastBottomY,
NaN,
NaN,
NaN,
NaN,
(last[16] - layerX) / layerWidth,
(last[17] - layerY) / layerHeight,
NaN,
Expand All @@ -631,7 +669,7 @@ class FreeOutliner {
}

const outline = new Float64Array(
this.#top.length + 12 + this.#bottom.length
this.#top.length + 24 + this.#bottom.length
);
let N = top.length;
for (let i = 0; i < N; i += 2) {
Expand All @@ -642,6 +680,7 @@ class FreeOutliner {
outline[i] = top[i];
outline[i + 1] = top[i + 1];
}

outline.set(
[
NaN,
Expand All @@ -654,12 +693,24 @@ class FreeOutliner {
NaN,
NaN,
NaN,
lastTopX,
lastTopY,
NaN,
NaN,
NaN,
NaN,
lastBottomX,
lastBottomY,
NaN,
NaN,
NaN,
NaN,
(lastBottom[0] - layerX) / layerWidth,
(lastBottom[1] - layerY) / layerHeight,
],
N
);
N += 12;
N += 24;

for (let i = bottom.length - 6; i >= 6; i -= 6) {
for (let j = 0; j < 6; j += 2) {
Expand Down