Git Product home page Git Product logo

craft-extension-api's Issues

`getTextSelection` does not return a string

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.