EzDevInfo.com

Caret.js

Get caret postion and offset from text field Caret.js

Use of caret symbol( ^ ) in Ruby

1 ^ 1
# => 0

1 ^ 2
# => 3

5 ^ 6
# => 3

These are the results I am getting. Can, please, somebody explain how ^ works?


Source: (StackOverflow)

How do I get window.getselection to work for an input type=text field

I have a contenteditable div, like so:

<div id="test" contentEditable="true" style="width: 600px; height:300px;">Lorem ipsum dolor sit amet</div>

for which I use the following code:

<input type="button" value="Click me" onclick="alert(window.getSelection().focusOffset.toString());"></button>

Clicking on the button when I move the caret around in the div, returns to me the actual position (offset) of the caret within the div.

The problem is when I replace the contenteditable div with an input type=text or password control, and keep the contenteditable property=true, and click on the button, I always get a zero. Why is this?

Thanks for looking.


Source: (StackOverflow)

Advertisements

Caret position in textarea, in characters from the start

How do you get the caret position in text area using JavaScript?

For example:
This is| a text

This should return 7.

How would you get it to return the strings surrounding the cursor/selection? eg:

'This is', '', ' a text'
If the word "is" is highlighted, then it would return 'This ', 'is', ' a text'


Source: (StackOverflow)

How to avoid cmd.exe interpreting shell special characters like < > ^

I have a Windows CMD script that accepts a number of parameters and executes an EXE, passing first some hard-coded arguments and then all of the parameters from the user. The CMD script looks like this:

launcher.exe paramX paramY %*

The user would execute the CMD script from the Windows shell as follows:

launcher.cmd param1 param2 param3 [...]

The problem I have is that if the parameters to the CMD script contain shell special characters like < > and ^, the user is forced to escape these by preceding each with 3 caret ^ shell escape characters.

Two Examples

1) To pass the argument ten>one to the EXE, the user must launch the CMD as follows:

launcher.cmd ten^^^>one

The reason for this is that the shell special characters ^ and > are interpreted by the command shell at two levels, first on the command line and second inside the CMD script. So, the shell escaping with the caret ^ shell escape character must be applied twice. The problem is that this is non-obvious to the user and looks ugly.

For this example, a nicer solution is to surround the argument with double quotes. However, this breaks down for more complex examples that include a literal double quote in the argument.

2) To pass the argument "^ to the EXE, the user must launch the CMD as follows:

launcher.cmd "\"^^^^"

In my case I want to support arguments that contain any sequence of low ASCII characters, excluding control characters, i.e. code points 0x20 to 0x7E. I understand that there will be examples where the user will have to escape certain shell special characters with a caret. However, I don't want the user to have to use 3 carets every time in these cases just because they happen to be calling a CMD script instead of an EXE.

I can solve this problem by replacing the CMD script with an EXE that does the same. However, is there any way to alter the CMD script so that it passes its parameters through to the EXE without interpreting the shell special characters?


Source: (StackOverflow)

Caret positition / Selection inside DIV, Textbox, Textarea, etc

Is there a total solution for getting a caret position and/or selection inside every browser from different elements. I'm looking for a solution witch I can execute like mGetCaretPosition(iControl) witch will return the caret position inside it`s element.

I have tried a lot of functions:

  • selection (window/document) [document=IE, window=Opera]
  • getSelection (window/document) [document=Firefox, document=Chrome, document=Safari]
  • selectionStart (input/textarea) [All]
  • craeteRange (selection)
  • createTextRange (selection)


Calling a method like document.selection.createRange().text doesn't return a caret position because it doesn't have a selection. When setting tRange.moveStart('character', -X) the X isn't a known value. When you use this inside a div and the caret is in the middle it takes the code before the div.


Source: (StackOverflow)

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

I'm working on a jQuery plugin that will allow you to do @username style tags, like Facebook does in their status update input box.

My problem is, that even after hours of researching and experimenting, it seems REALLY hard to simply move the caret. I've managed to inject the <a> tag with someone's name, but placing the caret after it seems like rocket science, specially if it's supposed work in all browsers.

And I haven't even looked into replacing the typed @username text with the tag yet, rather than just injecting it as I'm doing right now... lol

There's a ton of questions about working with contenteditable here on Stack Overflow, and I think I've read all of them, but they don't really cover properly what I need. So any more information anyone can provide would be great :)


Source: (StackOverflow)

How to retain selected text in JTextField when focus lost?

Now finishing my custom menu popup, but the problem is that if I select some text in JTextField and click mouse button to show popup menu, then focus is transferred to popup window, AND selected text before are no longer highlighted. When focus is back to JTextField - selected text become highlighted again. How to make the selected text stay highlighted on focus lost?


Source: (StackOverflow)

Java: column number and line number of cursor's current position

I want to know the column number and row number where the cursor in JTextArea. ie. in notepad when i m at first line than status bar shows Ln 1, Col 1.

thanks in advance...


Source: (StackOverflow)

Auto text scroll for text area (JTextArea) with caret position set to the beginning of the last line

I have a simple Java question here. I want to auto text scroll to the beginning of the last line of a text area created using JTextArea. The amount of text per line of the text area is quite longer than the width of the text area.

Here is the code snippet I used to set that up.

JTextArea textArea = new JTextArea();
DefaultCaret caret = (DefaultCaret)textArea.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

The problem now is, with the above code, the default behavior is that the caret is auto positioned to the end of the document, as a result, the beginning part of the whole text area gets out of scope. I'd prefer the auto scroll to happen to the beginning of the last line in the document.

To make it clear, here are two screen shots,

What I want is the first one but what's happening is the second one.

What I want is this What I get is this


Source: (StackOverflow)

How can I get the element the caret is in with Javascript, when using contentEditable?

Let's say I have some HTML code like this:

<body contentEditable="true">
   <h1>Some heading text here</h1>
   <p>Some text here</p>
</body>

Now the caret (the blinking cursor) is blinking inside the H1 element, let's say in the word "heading". How can I get the name of the element the caret is in with JavaScript? Here I would like to get "h1".

This needs to work only in WebKit (it's embeded in an application). It should preferably also work for selections.

If this is truly trivial, I apologize. My knowledge of JavaScript (and DOM) is sorely lacking.


Source: (StackOverflow)

Why 10^1 is 11?

I am currently learning C++. I was trying to compute power of an integer using the expression:

val=10^1;

Instead of expected answer 10, the result was 11. I have fixed the problem by using pow function of math.h library but I am wondering why this statement is giving me the wrong result.


Source: (StackOverflow)

Preprocessor macro using caret ^ symbol at the start of an expression

Looking at this page: http://www.mikeash.com/pyblog/friday-qa-2010-12-31-c-macro-tips-and-tricks.html

I found this snippet of code with ^{ ... }() syntax, what are the caret/brackets doing?

#define MAX(x, y) (^{ \
    int my_localx = (x); \
    int my_localy = (y); \
    return my_localx > my_localy ? (my_localx) : (my_localy); \
}())

It looks like its creating an anonymous function or something. What is this concept called? Where can I read about it?


Source: (StackOverflow)

Changing bootstrap caret(color and position)

Can anyone help me: I want to change color of caret and make it not relative from input text, because it's hard to make it look good when it is.


Source: (StackOverflow)

Get caret position in HTML input?

How do I get the index of the text caret in an input?


Source: (StackOverflow)

How to have transparent fonts except for the 'text-caret' in a textarea?

I have a simple textarea and I need to make transparent letters while allowing the text-caret to be visible. When I apply the following rules then I get invisible caret:

textarea {
   background: transparent;
   opacity: 0;
}

When I type invisible text, I need to see the text-caret move.

EDIT: I need to make editor to edit td cell in table. When I click on a cell I show a textarea and start typing. On a each character letter, I insert a context in a cell. After that, I hide a textarea.


Source: (StackOverflow)