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

Property 'caretPositionFromPoint' does not exist on type 'Document' #49931

Closed
Egor-Koldasov opened this issue Jul 17, 2022 · 6 comments
Closed
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@Egor-Koldasov
Copy link

Bug Report

πŸ”Ž Search Terms

caretPositionFromPoint
Property 'caretPositionFromPoint' does not exist on type 'Document'

πŸ•— Version & Regression Information

  • This changed between versions 4.3.5 and 4.4.2

⏯ Playground Link

Doesn't work in 4.4.4: Playground link
Works in 4.3.5: Playground link

πŸ’» Code

if (document.caretPositionFromPoint) document.caretPositionFromPoint(0, 0);

πŸ™ Actual behavior

'Document' should have an optional property "caretPositionFromPoint" since it exists in Firefox browser. Link.

πŸ™‚ Expected behavior

Property "caretPositionFromPoint" has been removed from 'Document', I was not able to find an explanation of this decision.

@MartinJohns
Copy link
Contributor

It was removed here: microsoft/TypeScript-DOM-lib-generator#1029

Probably because it's an experimental API with close to no browser support: https://developer.mozilla.org/en-US/docs/Web/API/Document/caretPositionFromPoint

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jul 18, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@mike-lischke
Copy link

Still the wrong decision IMO. The alternative document.caretRangeFromPoint is deprecated and without document.caretPositionFromPoint there's no alternative to use. The variant document.caretPositionFromPoint works in Firefox and web devs need to test for it either to use this or the alternative. How are we supposed to do that, if there's no entry for the method we need to test?

@mgiraldo
Copy link

mgiraldo commented Mar 6, 2023

i'm in this exact situation. i need to support either method for the different browsers that support them... kind of:

let range;

if (document.caretRangeFromPoint) {
  range = document.caretRangeFromPoint(x, y)
} else {
  range = document.caretPositionFromPoint(x, y)
}

is there a shim i can add to have Document include caretPositionFromPoint?

@raphael10-collab
Copy link

I totally agree with @mike-lischke

We need the type-support for both caretPositionFromPoint and caretRangeFromPoint : https://developer.mozilla.org/en-US/docs/Web/API/Document/caretPositionFromPoint#examples

@vogon
Copy link

vogon commented May 2, 2024

#49931 (comment) it's been a year since you left this comment, so hopefully you got some help elsewhere by now, but for anyone else who wants a quick shim for this, here's what I'm using:

declare global {
    type CaretPosition = {
        offsetNode: Node;
        offset: number;
    }

    interface Document {
        caretPositionFromPoint?(x: number, y: number): CaretPosition;
    }
}

it doesn't support getClientRect() on CaretPosition, but that wasn't necessary for our use case and hopefully it should be straightforward enough to figure out its declaration if it is for yours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

8 participants