Tag-like autocompletion and caret/cursor movement in contenteditable elements

You could use my Rangy library, which attempts with some success to normalize browser range and selection implementations. If you’ve managed to insert the <a> as you say and you’ve got it in a variable called aElement, you can do the following: var range = rangy.createRange(); range.setStartAfter(aElement); range.collapse(true); var sel = rangy.getSelection(); sel.removeAllRanges(); sel.addRange(range);

jquery Setting cursor position in contenteditable div

Maybe I’m misreading the question, but wouldn’t the following do (assuming an editable <div> with id “editable”)? The timer is there because in Chrome, the native browser behaviour that selects the whole element seems to trigger after the focus event, thereby overriding the effect of the selection code unless postponed until after the focus event: … Read more

Custom Caret for WinForms TextBox

These are the list of Native Caret functions provided by Windows you can use them for you application. [DllImport(“User32.dll”)] static extern bool CreateCaret(IntPtr hWnd, int hBitmap, int nWidth, int nHeight); [DllImport(“User32.dll”)] static extern bool SetCaretPos(int x, int y); [DllImport(“User32.dll”)] static extern bool DestroyCaret(); [DllImport(“User32.dll”)] static extern bool ShowCaret(IntPtr hWnd); [DllImport(“User32.dll”)] static extern bool HideCaret(IntPtr hWnd); … Read more

Javascript: Move caret to last character

The following function will work in all major browsers, for both textareas and text inputs: function moveCaretToEnd(el) { if (typeof el.selectionStart == “number”) { el.selectionStart = el.selectionEnd = el.value.length; } else if (typeof el.createTextRange != “undefined”) { el.focus(); var range = el.createTextRange(); range.collapse(false); range.select(); } } However, you really shouldn’t do this whenever the user … Read more

Set the caret/cursor position to the end of the string value WPF textbox

You can set the caret position using CaretIndex property of a TextBox. Please bear in mind that this is not a DependencyProperty. Nevertheless, you may still set it in XAML like this: <TextBox Text=”123″ CaretIndex=”{x:Static System:Int32.MaxValue}” /> Please remember to set CaretIndex after Text property or else it will not work. Thus it probably won’t … Read more

Caret character between types rather than variables, surrounded by parentheses

These are blocks which add anonymous functions and function objects to Objective-C. See e.g. Introducing Blocks and Grand Central Dispatch : Block objects (informally, “blocks”) are an extension to C, as well as Objective-C and C++, that make it easy for programmers to define self-contained units of work. Blocks are similar to — but far … Read more

How to get the focused element with jQuery?

// Get the focused element: var $focused = $(‘:focus’); // No jQuery: var focused = document.activeElement; // Does the element have focus: var hasFocus = $(‘foo’).is(‘:focus’); // No jQuery: elem === elem.ownerDocument.activeElement; Which one should you use? quoting the jQuery docs: As with other pseudo-class selectors (those that begin with a “:”), it is recommended … Read more