selection

window.getSelection() offset with HTML tags?

你。 提交于 2020-01-13 02:41:08
问题 If I have the following HTML: <div class="content"> Vivamus <span>luctus</span> urna sed urna ultricies ac tempor dui sagittis. </div> And I run an event on mouseup that sees the ranges of the selected text: $(".content").on("mouseup", function () { var start = window.getSelection().baseOffset; var end = window.getSelection().focusOffset; if (start < end) { var start = window.getSelection().baseOffset; var end = window.getSelection().focusOffset; } else { var start = window.getSelection()

prevent listview to lose selected item

谁说我不能喝 提交于 2020-01-11 08:33:12
问题 I'm currently working on a listview in winform c# and everytime I click on an empty space on the listview, the selected item is lost. 回答1: The listview control has a HideSelection property that defaults to True . Make it False and you're good to go... in some cases this is enough. 回答2: I thought there was a property that prevented this from happening, but now I can't find it. You could try this: private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { ListView

Index of selected words using Javascript

不羁岁月 提交于 2020-01-11 04:10:21
问题 How can I get the index of selected text in HTML using Javascript? For example, in an HTML file, there is paragraph like the following: I am living in India. India is the very beautiful country. Now if the user selects India in the first sentence then there should be an alert 5 and if the user selects India of second line then there is an alert 6 . How can I get the index of the word that the user selected? 回答1: You could do this with the new TextRange module of my Rangy library. Rangy's

selectionStart and selectionEnd in contenteditable element

孤街醉人 提交于 2020-01-10 17:26:49
问题 I have been struggling the selectionStart and selectionEnd attributes of textarea to make them work with contenteditable div element. I have checked a lot of related articles on google and on SO but to no avail. I have something similar to the following which is working for textarea perfectly. But I want this one to work with contenteditable div. function replaceVal(node, val, step){ //... var cursorLoc = node.selectionStart; node.value = node.value.substring(0, node.selectionStart - step) +

selectionStart and selectionEnd in contenteditable element

雨燕双飞 提交于 2020-01-10 17:25:09
问题 I have been struggling the selectionStart and selectionEnd attributes of textarea to make them work with contenteditable div element. I have checked a lot of related articles on google and on SO but to no avail. I have something similar to the following which is working for textarea perfectly. But I want this one to work with contenteditable div. function replaceVal(node, val, step){ //... var cursorLoc = node.selectionStart; node.value = node.value.substring(0, node.selectionStart - step) +

“Application.Calculation = xlCalculationManual” statement causing run-time error 1004 in VBA Copy-Paste procedure

六眼飞鱼酱① 提交于 2020-01-10 05:17:07
问题 I have VBA code that copies the first row and pastes the values to multiple rows. The below code runs fine and pastes the rows as expected: Sub Macro1() Dim i As Long Application.Calculation = xlCalculationManual Range("A1:M1").Select Selection.Copy For i = 1 To 50 Range("A" & i).Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Next i End Sub However, if I move Application.Calculation = xlCalculationManual down two lines as below,

Remove All id Attributes from nodes in a Range of Fragment

試著忘記壹切 提交于 2020-01-07 04:15:10
问题 Is there a way to remove the id attribute of every node in a range or fragment? Update: I finally found out that the bug I'm struggling with is based on a <[script]> being included in a range, and therefore unexpectedly cloned, when a chrome user does a ctrl+a. My goal would be to remove any instance of <[script]> from the range (or doc fragment), such that it is not replicated when cloned. 回答1: You may be able to use a TreeWalker, which works in pretty much all the browers that Range works

Which is the fastest algorthm for selecting kth largest number in an unsorted array containing non -unique elements? [duplicate]

时间秒杀一切 提交于 2020-01-06 19:59:28
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to find the kth largest element in an unsorted array of length n in O(n)? The number of elements can vary from 1 to 10 million .Which is the fastest selection algorithm available for this purpose? Please note I think data structures like AVL Trees won't work here due to duplication of array elements? 回答1: A selection algorithm can run in O(N) time. The most general way is to make a pass through the array,

Trouble with storing enter selections containing transitions

半世苍凉 提交于 2020-01-06 01:36:19
问题 If I try to store the following enter selection, I get an error when I try to access it. I don't have a problem if I remove the transition. Why? Are there other restrictions on storing selections? Here is an example: // this works var enterSel = d3.select("svg") .selectAll("circle") .data([100, 200, 300]) .enter() .append("circle") .attr("cx", d => d) .attr("cy", "100") .attr("fill", "red") .attr("r", "0") .transition() .duration(2000) .attr("r", "50"); The above appends and transitions three

Getting IE to load a different js file

北战南征 提交于 2020-01-04 07:19:22
问题 Trying to get a page to load a different js file if the browser is IE, but a different one if it is any other browser. I've corrupted this, but it won't work, does anyone have any ideas? Any help is appreciated: <script type="text/javascript"> var ie = false; </script> <!--[if IE]> <script type="text/javascript"> ie = true; </script> <![endif]--> <script type="text/javascript"> if(ie == false) { document.write ("<script src="js/moreskins.js" type="text/javascript">")</script>; } else {