Giter Club home page Giter Club logo

caret.js's People

Contributors

hnrch02 avatar ichord avatar insign avatar martinvd avatar mociepka avatar sbrudz avatar tiye avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

caret.js's Issues

Few extra pixels in top position

Hello!
I have a textarea with font-size=14px, line-height=20px and padding=40px.
When I try to get top position of any character, I get 40 (padding) + linesBefore*20 + 2px.

Here is a fiddle with demo: http://jsfiddle.net/gkalabin/aeHNj/
The output is
A position is {"left":40,"top":42,"height":16}
B position is {"left":40,"top":62,"height":16}
G position is {"left":40,"top":162,"height":16}

What are these 2 extra pixels? How can I get rid of them?

Also, If you change font-size then the extra can vary from -1 (18px) to 3 (12px)

Cursor Position is Horribly Wrong

Hey there,

I've got an issue using the cursor position where it's incredibly wrong. I typed in the following
123456789 123456789

My cursor was at the end and it said it was at 33

The format of my code is a contentEditable div with a

inside so I can create line numbers using the :before psuedoelement

Is there a reason why the cursor position is so wrong?

Thanks!

  • IAmDragon

Make all function work in ie

something like this

Know how to solve this problem now, but no IE browsers yet.
Let me find an Windows first..= =

$("#inputor").caret("offset", 50);

$("#inputor").caret("position");
$("#inputor").caret("position", 12);

Problem with HTML entities

First of all, awesome job. At.js worked amazingly; I really appreciate all your work!

I did find one small bug:

http://ichord.github.io/Caret.js/

Try typing out a sentence then add "&", for example. It should be easy enough to fix by converting & to & before writing it to the DOM.

Thanks again!

CodeMirror support

Is there an easy way how to make Caret.js + At.js work with CodeMirror or any other code editor? It doesn't seem they are contenteditable based.

Mirror div does not reset its CSS

Caret.js works by creating a mirror of the textarea as a div and copies the CSS of the textarea.

In our application, we had CSS rules that is applying positioning on span's that Caret.js creates in the mirror div.

This causes caret.js to miscalculates the position of the caret. I will try to come up with a simple test case that illustrates the issue.

$dom[0] is undefined

I've recently started using Caret.js in order to use atWho.js. I'm using it on a rails app and have installed it two ways. First using the jquery-atwho-rails gem, and then manually installing caret.js and atwho.js. Both times I'm getting the following error:

TypeError: $dom[0] is undefined
oDocument = $dom[0].ownerDocument;

It's happening here specifically on line 366:

configure = function($dom, settings) {
      var error, iframe;
      if ($.isPlainObject(settings) && (iframe = settings.iframe)) {
        $dom.data('caret-iframe', iframe);
        return setContextBy(iframe);
      } else if (iframe = $dom.data('caret-iframe')) {
        return setContextBy(iframe);
      } else {
        oDocument = $dom[0].ownerDocument;
        oWindow = oDocument.defaultView || oDocument.parentWindow;
        try {
          return oFrame = oWindow.frameElement;
        } catch (_error) {
          error = _error;
        }
      }
    };

Not sure what's causing that or how to fix it, any suggestions?

好像在contenteditable div 里有问题。

你好,感谢你的工作。
我使用Caret.js控制caret,在input 和 textarea里一切正常,在div里使用caret('pos', num)不能正常工作。
另外一个小问题是同样在div里,输入第一个字符时就不能使用caret('offset')获得caret的position,接着输入就没有问题。
不知道我说清楚了没有,谢谢。

Problems with Chinese and Japanese characters

Hi.
I have a problem when entering the Korean and Japanese characters in kontenteditavle.
The symbols are repeated if you press the arrow keys or space. You can will see on the page with a demonstration script

Support for text fields (input[type=text]) in addition to textarea

Currently, Caret only fully supports textareas, because of a difference in input vs textarea. The biggest time you see this problem is when you type past the visible end of a text field (so your text scrolls left/right). Because of the expectation for it to behave like a textarea, the position calculations get thrown way off.

There probably needs to be a special code-path for text fields, where width is not applied to the mirror span's CSS, and it's treated as being "infinitely wide". From a quick test where width is just not applied, that seems to improve position detection.

Editable.setPos

If someone will ned - I've used for contenteditable :

       EditableCaret.prototype.setPos = function(pos) {
            var inputor, range;
            inputor = this.domInputor;

            if ( oDocument.getSelection ) {
                var selection = oDocument.getSelection(), node;
                range = selection.getRangeAt( 0 );

                var getNode = function ( node ) {
                    if ( node.childNodes.length > 0 ) {
                        for ( var i = 0; i < node.childNodes.length; i++ ) {
                            var childNode = getNode( node.childNodes[i] );
                            if ( length < pos )
                                continue;
                            return childNode;
                        }
                    } else if( node.nodeType === 3 ) {
                        length += node.nodeValue.length;
                        if( pos <= length  &&  $( node ).closest( '*[contenteditable]' ).attr('contenteditable') == 'false'  ){
                            pos += ( length - pos )+1;
                        }
                        return node;
                    }
                }

                if ( inputor.childNodes.length > 0 ) {
                    var length = 0;
                    for ( var i = 0; i < inputor.childNodes.length; i++ ) {
                        node = getNode( inputor.childNodes[i] );
                        if ( length < pos )
                            continue;
                        break;
                    }
                    if ( length < pos ) {
                        range.setEnd( node, node.nodeValue.length );
                    }
                    else {
                        range.setEnd( node, pos - length + node.nodeValue.length );
                    }
                } else {
                    range.setEnd( inputor, Math.min( pos, inputor.nodeValue.length ) );
                }

                range.collapse( false );
                selection.removeAllRanges();
                selection.addRange( range );

            }  else if ( inputor.setSelectionRange ) {
                inputor.setSelectionRange( pos, pos );
            }
            return inputor;
        };

Providing the minified file in the repo

your At.js plugin provides the minified files in a dist/ folder. It would be great if you could do the same for caret.js (previously, I was not caring about it as jquery.atwho.js was including caret in the minified file)

bug in IE9-11

when mouseenter the iframe there's an error: SCRIPT5022: WrongDocumentError file: jquery.caret.js,line: 105,column: 13 in IE9-11

Clicking to set cursor before first character in ContentEditable element inserts rogue character and loses focus

There seems to be a bug when clicking directly before the first character in a ContentEditable element. After the click, the ContentEditable cursor disappears and a rogue character is inserted into the editor.

I think this has to do with trying to detach the shadow cursor in EditableCaret.prototype.getOffset method.

I'm trying to debug it and will roll in a patch if I can figure it out... just thought I'd add it as an issue here in case it's an easy fix that I'm missing.

What is "inputor"?

Not talking about the ID, but the word in the README:

Get caret postion or offset from inputor

Does it mean text area + input type="text", or other input elements (contenteditable)?

Thank you

Seriously, I spent days trying to find the best solution to this problem, and you've just probably saved me another few weeks of bug fixing and tedious code.

Thank you for sharing your hard work, you're awesome :)

Bad positioning in long words

Hello!

Here is a screenshot (there is no line breaks in textarea's content, the text is wrapped by the browser itself):
screenshot_2014_06_30__17_51_02

The problem is that you copy to mirror div just a substring(0, caretPos).
In case of the caret in long word (0123456789 in the screenshot) you will copy some part of the word (012). So in case of textarea the word is wrapped (there is no room for 0123456789), but in case of the mirror there is space for 012.

Caret.js and Browserify

I'm trying to get this module to work with Browserify but I'm failing to extend jQuery with the error Uncaught TypeError: $(...).caret is not a function. Here's my code:

global.jQuery = require "jquery"
require "jquery.caret" #  package.json -> "browser": { "jquery.caret": "./node_modules/jquery.caret/dist/jquery.caret.js"  }

$ ->
  console.log $("div").caret("position")

Where am I going wrong?

wrong position when text wraps

when text wraps in a textbox or contentEditable div the cursor can be set at the end of the first line (after the last space) or the beginning of the second line and it will say the cursor is on the second line

image

$inputor not defined

I am getting an error when using this in IE. The error goes away if I qualify $inputor as this.$inputor, as below, but it doesn't put the box in the correct place.

  Caret.prototype.getIEOffset = function(pos) {
    var h, range, x, y;

    range = this.domInputor.createTextRange();
    if (pos) {
      range.move('character', pos);
    }
    x = range.boundingLeft + this.$inputor.scrollLeft();
    y = range.boundingTop + $(window).scrollTop() + this.$inputor.scrollTop();
    h = range.boundingHeight;
    return {
      left: x,
      top: y,
      height: h
    };
  };

Not working inside a shadow root

The Library doesn't work if the input (or contenteditable) is inside a shadow root since window.getSelection doesn't work there (shadow_root.getSelection would be the right method to be called)

Document procedure to build from source

Many of the files in the VCS repository are actually build artefacts: the JavaScript library is evidently generated from a CoffeScript source, for example.

Please document which files are mechanically generated, and the full procedure for generating them from source. The goal is to describe what a recipient needs to do to build from (maybe customised) source, the same way the maintainers do it.

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.