Giter VIP home page Giter VIP logo

Comments (5)

bergie avatar bergie commented on August 22, 2024

Fixed by ea0084c

from hallo.

DanielSmedegaardBuus avatar DanielSmedegaardBuus commented on August 22, 2024

This seems to have been reintroduced after the jQuery.browser fix in 1.0.2, or is it just me? I cannot get the new one to insert links anymore — the selection is immediately lost when the dialog is opened, and ultimately adding the link does not succeed.

from hallo.

DanielSmedegaardBuus avatar DanielSmedegaardBuus commented on August 22, 2024

Okay, it's pretty funky. After a boatload of headscratching, trying to pinpoint where the issue lay, and also trying to use the rangy save and restore module instead of the internal Hallo logic, I finally discovered that it's some kind of synchronicity issue.

Wrapping the selection restore statement and the create link statement in a settimeout call with just a very small delay, like 100ms, and voilà! Everything works properly.

This is pretty far from what anyone would call a fix, though, and I'm guessing the problem would surface elsewhere, too, unless the real issue is addressed. I'm just not too into the whole codebase to give an educated guess as to what may be causing this.

This is in Chrome, btw., and I just gave it a test run in Firefox. Here, no timeout hack is needed — it just works.

I experienced the behavior occasionally with the previous revision in Chrome, but it only happened with specific editables, and not consistently with those either. That's not to say that any change in the new revision may have caused it, because I've also updated other libraries since then.

Perhaps this is a webkit bug introduced by some kind of aggressive JS optimizations?

from hallo.

DanielSmedegaardBuus avatar DanielSmedegaardBuus commented on August 22, 2024

Specifically, and this is JS, sorry — still don't really know Coffee Scripts:

      if (widget.lastSelection.startContainer.parentNode.href === void 0) {
        setTimeout(function () {
          widget.options.editable.restoreSelection(widget.lastSelection);
          document.execCommand("createLink", null, link);
        }, 100);
      } else {

The interesting thing here is that it's the restoreSelection that must be delayed. The first call (made before these lines of code) isn't successful.

from hallo.

DanielSmedegaardBuus avatar DanielSmedegaardBuus commented on August 22, 2024

Okay, some further details. Thinking synchronicity issues, I browsed through the Rangy code and the Hallo code, and AFAICT no asynchronus code is being executed in restoring the selection, nor in the surrounding code.

What I've discovered is that Chrome will fail to restore the selection so long as the jQuery UI modal is open. This is true for the Hallo selection restore logic as well as for the Rangy one (saveSelection() / restoreSelection()). If I set a timeout on the selection restoriation and link insertion of, say, 2 seconds, and a timeout on the closing of the modal of, say, 4 seconds, the operation will still fail. (But still succeed in Firefox (and you can see the selection reappearing at 2 seconds in)).

If I don't use timeout hacks at all, but instead close the modal immediately after reading the value of the URL input field, everything works as expected.

I'm not sure what the issue is, but it's clear to me that the presence of the modal prevents the selection restoration from succeeding. I'm thinking it's a Rangy or Chrome issue rather than a Hallo one, though.

In either event — the quick fix is to close the modal as soon as it's no longer needed and before doing DOM modifications of any kind. Perhaps also for modals other than the link module, not sure :)

Either way, illustrated: DanielSmedegaardBuus@6fcc4d1

from hallo.

Related Issues (20)

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.