Skip to content

getTextSelection does not return a string #2

@motform

Description

@motform

Like craftdocs/craft-extension-inspirations#6, I am also getting behaviour (macOS app 2.1.6) where getTextSelection seemingly succeeds but returns the empty string.

const selection = async () => {
	const response = await craft.editorApi.getTextSelection();
	if (response.status !== "success") throw new Error(response.message);

	let selectedText = response.data;
	if (selectedText.length === 0) selectedText = "Text selection is of len 0.";

	const block = craft.blockFactory.textBlock({
		content: selectedText
	});

	craft.dataApi.addBlocks([block]);
}

 
Consistently creates a block with Text selection is of len 0., regardless of I have text selected (which I would assume would give me the selected text) or if I don't have any selection. The latter seems like an API oversight, as I would have intuitively assumed that status fails on no selection.

I wanted to build a small capitalisation utility, but I don't see how you can do that without something as granular as getTextSelection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions