selection

Keep text selection when focus changes

时光毁灭记忆、已成空白 提交于 2019-12-17 19:52:37
问题 I have a normal textbox, and a lightbox with a text input. I want to keep the user's selection in the textbox, even when the user focuses on the lightbox's text input. Select text in normal textbox Toggle lightbox Focus on lightbox input At step 3., the user's text selection is discarded. How can this be prevented? See Google docs link insertion lightbox for example. Thanks :) Update Ok, so Google docs uses an iframe for the blank page section, which is how they are handling the multiple

How to get the user selection from startActivityForResult(Intent.createChooser(fileIntent, “Open file using…”), APP_PICKED);?

你。 提交于 2019-12-17 19:44:08
问题 Is there any way to get programmatically the user selection after startActivityForResult(Intent.createChooser(fileIntent, "Open file using..."), APP_PICKED); or startActivity(Intent.createChooser(fileIntent, "Open file using...")); I do not want to start the selected application - I only want to know which one is it? Thanks! 回答1: No, you cannot find out what the user chose. You can, however, use PackageManager and queryIntentActivities() to make your own chooser. 来源: https://stackoverflow.com

Set caret position at a specific position in contenteditable div

主宰稳场 提交于 2019-12-17 18:41:21
问题 SEE BEFORE MARKING DUPLICATE/DOWNVOTING The contenteditable div will not have child elements I do not want to set the position at the end of the div I do not want a cross-browser solution , only Chrome support required Only vanilla JS , no libraries. I have seen many many solutions. Many by Tim Down, and others. But none does work. I have seen window.getSelection , .addRange etc. but don't see how they apply here. Here's a jsfiddle. (Tried) Code: var node = document.querySelector("div"); node

Set textarea selection in Internet Explorer

时光总嘲笑我的痴心妄想 提交于 2019-12-17 15:56:22
问题 I'm looking for a way to set a selection in a textarea in Internet Explorer. In other browsers, this works just fine: textarea.selectionStart = start; textarea.selectionEnd = end; In IE, I assume I have to use createRange and adjust the selection somehow, but I cannot figure out how. Extra bonus points for a link to a proper documentation about createRange and associated methods, MSDN isn't helping out much. 回答1: This works for me: <textarea id="lol">

Android Spinner selection

痴心易碎 提交于 2019-12-17 15:36:32
问题 The OnItemSelectedListener event handler gets called both when a spinner selection is changed programmatically, and when a user physically clicks the spinner control. Is is possible to determine if an event was triggered by a user selection somehow? Or is there another way to handle spinner user selections? 回答1: To workaround you need to remember the last selected position. Then inside of your spinner listener compare the last selected position with the new one. If they are different, then

Create a ListView with selectable rows/change background color of ListView rows when clicked

守給你的承諾、 提交于 2019-12-17 09:58:52
问题 Problem I'm trying to create a ListView with selectable items. I want to be able to click on an item in the ListView and have the item change color in the list, and then go on and do something else with the data from the row. I'm using a SimpleAdapter . How do I make it so that when I tap on a row, it turns a different color, and then when I tap on a different row, the new row is selected and changed to a new color, and the old row changes back to normal? Code Here is my code so far. The

Calculate Position of selected text javascript/JQuery?

心不动则不痛 提交于 2019-12-17 07:27:29
问题 How to retrieve the position of selected text by calculating it's offset immediate after body tag? For Example consider the following html, <body> <div>hi</div> <div>dude!</div> </body> on selecting from "i" (in hi) to "du" (in dude), I need to get 2 as start position & 4 as end position. Note: Ignore the tag elements. Javascript is preferable! 回答1: Here's some simple, naive code to do this that may well do the job for your use case. It does not take into account any text that may be made

How To Wrap / Surround Highlighted Text With An Element

可紊 提交于 2019-12-17 01:01:37
问题 I want to wrap a selected text in a div container with span, is it possible? A user will select a text and will click a button, on button click event I want to wrap that selected text with span element. I can get the selected text using window.getSelection() but how to know its exact position in DOM structure? 回答1: If the selection is completely contained within a single text node, you can do this using the surroundContents() method of the range you obtain from the selection. However, this is

How To Wrap / Surround Highlighted Text With An Element

安稳与你 提交于 2019-12-17 01:01:14
问题 I want to wrap a selected text in a div container with span, is it possible? A user will select a text and will click a button, on button click event I want to wrap that selected text with span element. I can get the selected text using window.getSelection() but how to know its exact position in DOM structure? 回答1: If the selection is completely contained within a single text node, you can do this using the surroundContents() method of the range you obtain from the selection. However, this is

D3 js set data from data-attribute

元气小坏坏 提交于 2019-12-14 04:19:25
问题 During creating graphs I need to set data. Those data(Array of Objects) I have already in HTML like this: <svg class="graph-n" data-stuff="{simplified data}"></svg> Then with Javascript and D3 JS I initialize and setup graphs with the following code: <script> var margin = { top: 20, right: 20, bottom: 30, left: 50}, width = 1500 - margin.left - margin.right, height = 350 - margin.top - margin.bottom; var x = d3.scaleTime().range([0, width]); var y = d3.scaleLinear().range([height, 0]); var