lens icon indicating copy to clipboard operation
lens copied to clipboard

Find a better solution to update the contextId prop of the Scrollbar

Open michael opened this issue 10 years ago • 0 comments

Currently we solve it like this:

In lens_writer.js:


  this.handleStateUpdate = function(newState) {
    // var oldState = this.state;
    var doc = this.getDocument();

    function getActiveNodes(state) {
      if (state.citationId) {
        var targets = doc.get(state.citationId).targets;
        return [ state.citationId ].concat(targets);
      }
      return [];
    }

    var activeAnnos = getActiveNodes(newState);
    // HACK: updates the highlights when state
    // transition has finished
    setTimeout(function() {
      doc.setHighlights(activeAnnos);  
    }, 0);
  };

And in content_panel.js it's also a bit smelly:

  this.onHighlightsUpdated = function(highlights) {
    var controller = this.context.controller;

    // Triggers a rerender
    this.refs.scrollbar.extendProps({
      highlights: highlights,
      contextId: controller.state.contextId
    });
  };

We do this just to reach some proper coloring of the scrollbar according to the current context. Maybe we find better solution.

michael avatar Oct 15 '15 18:10 michael