GithubHelp home page GithubHelp logo

chameleonhider / scroll-marker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from surdu/scroll-marker

0.0 1.0 0.0 44 KB

Provides scrollbar highlight functionality for Atom Editor

Home Page: https://atom.io/packages/scroll-marker

License: MIT License

JavaScript 90.13% CSS 9.87%

scroll-marker's Introduction

Scroll Marker

Build Status dependencies Status

This is a base package for Atom that provides the functionality for other atom packages (see list below) to highlight important things on the editor's scroll bar.

screen shot 2018-06-20 at 21 51 40

That means, in order to get any use out of this package, you also need to install one of the packages bellow.

Packages powered by Scroll Marker:

Name What it highlights
find-scroll-marker Search results.
lint-scroll-marker Lint errors found by linter, atom-ide-ui or nuclide.
highlight-selected Occurrences of the selected text. Scrollbar highlight requires enabling in the package settings.

Developer documentation

The next part is addressed to developers who want to use the services provided by this package in order to create their own scroll bar marker package or to add scroll bar highlight capabilities to their packages.

If you're new to Atom's Services API I would strongly encourage you to first read the documentation for Services API and their nice blog post about this topic.

The first thing that is needed is declare in your plugin's package.json that you want to consume the scroll-marker service:

{
  "name": "example-scroll-marker",
  "main": "lib/index.js",
  "version": "0.0.0",

  // ...

  "consumedServices": {
    "scroll-marker": {
      "versions": {
        "0.1.0": "consumeScrollMarker"
      }
    }
  }
}

Then, in your main js file (in this case lib/index.js) add the consumeScrollMarker method:

module.exports = {
  activate() {
    // ...
  },

  consumeScrollMarker(api) {
    // Use `api` here
  },

  deactivate() {
    // ...
  }
};

This will give you the reference to the scroll-marker API.

API

getLayer(editor, name, color)

Creates and returns a singleton instance of Marker Layer. That means there will be only one instance of Marker Layer for a given editor/name combination.

This Marker Layer instance is what you'll use to add/remove markers to the scroll bar. All Markers added to this layer will have the specified color.

Arguments:

  • editor - an editor instance, usually acquired by using observeTextEditors
  • name - a unique name for the layer, usually the name of your package
  • color - CSS color that you want the markers added to this layer to be

Example:

consumeScrollMarker(api) {
  atom.workspace.observeTextEditors(function(editor) {
    const layer = api.getLayer(editor, "example-layer", "#00ff00");
    // ...
  });
}

Marker Layer

addMarker(line)

Adds a marker on the marker layer at the specified line.

Arguments:

  • line - line number you want to add the marker to. Note that the first line number is 0.

Example:

consumeScrollMarker(api) {
  atom.workspace.observeTextEditors(function(editor) {
    const layer = api.getLayer(editor, "example-layer", "#00ff00");
    layer.addMarker(2);
  });
}

syncToMarkerLayer(markerLayer)

Sync the markers on the scroll marker layer with the markers on a DisplayMarkerLayer.

Arguments:

  • markerLayer - an instance of DisplayMarkerLayer that is usually used to highlight text in the editor

Example:

consumeScrollMarker(api) {
  atom.workspace.observeTextEditors(function(editor) {
    const scrollLayer = api.getLayer(editor, "example-layer", "#00ff00");
    // `findApi` was obtained similarly to `api` but from find-and-replace package
    const searchLayer = findApi.resultsMarkerLayerForTextEditor(editor);

    scrollLayer.syncToMarkerLayer(searchLayer);
  });
}

For a detailed syncToMarkerLayer working example you can checkout the find-scroll-marker source code.

scroll-marker's People

Contributors

chameleonhider avatar surdu avatar

Watchers

 avatar

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.