Skip to content

Commit

Permalink
Fixed computerCharacterBound code
Browse files Browse the repository at this point in the history
  • Loading branch information
captainbrosset committed Dec 21, 2023
1 parent 8b8f9e7 commit 87c9aed
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions edit-context/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -588,16 +588,16 @@ <h2>Editable CANVAS</h2>

function computeCharacterBound(offset) {
const widthBeforeChar = canvasCtx.measureText(editContext.text.substring(0, offset)).width;
const charSize = canvasCtx.measureText(editContext.text[offset]);
const charWidth = canvasCtx.measureText(editContext.text[offset]).width;

const charX = canvas.offsetLeft + TEXT_ANCHOR_X + widthBeforeChar;
const charY = canvas.offsetTop + TEXT_ANCHOR_Y;

return DOMRect.fromRect({
x: charX,
y: charY - charSize.height,
width: charSize.width,
height: charSize.emHeightAscent
y: charY - FONT_SIZE,
width: charWidth,
height: FONT_SIZE
});
}

Expand Down

0 comments on commit 87c9aed

Please sign in to comment.