Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Add highlight decorations - #2605

Merged
benogle merged 44 commits into
masterfrom
bo-ns-highlights
Jun 18, 2014
Merged

benogle merged 44 commits into
masterfrom
bo-ns-highlights

Conversation

@benogle

@benogle benogle commented Jun 13, 2014

Copy link
Copy Markdown
Contributor

This adds the ability to highlight ranges in the buffer tracked by markers. Just like find and replace does when you search for something, only more efficient. You write a little code:

marker = editor.markBufferRange([[4, 13], [5, 17]], invalidate: 'inside')
editor.addDecorationForMarker(marker, type: 'highlight', class: 'sweet-view')

marker = editor.markBufferRange([[12, 16], [12, 19]], invalidate: 'inside')
editor.addDecorationForMarker(marker, type: 'highlight', class: 'sweet-view')
.sweet-view .region {
  border-radius: 2px;
  background: rgba(255, 0, 0, 0.5);
}

And get this:
screen shot 2014-06-17 at 11 46 53 am

Changes

Some things changed from the previous iteration of decorations

  • All decorations are marker based. It made storage and rendering easier. There are 2 functions on editor that you need to be concerned with: addDecorationForMarker and removeDecorationForMarker
  • There are no more typeless decorations. You can apply to multiple decoration types by using an array: {type: ['gutter', 'line'], class: 'sweet-view'}
  • Rather than an option to handle softWrapped lines in gutter / line types, you specify a range of [[4, 0], [4, Infinity]] to apply it to the wrapped rows, and [[4, 0], [4, 0]] to only apply to the initial row.

See #2507 for the original decorations

Comment thread spec/editor-component-spec.coffee Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper matches up kinda weird with the other one... seems like they should have corresponding names.

@nathansobo

Copy link
Copy Markdown
Contributor

Incredibly excited for this.

Comment thread src/display-buffer.coffee Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nathansobo we should filter here.

benogle added 5 commits June 16, 2014 16:05
This reduces the number of intermediate objects we need to create. The 
downside is a bit more code complexity in the components.
@benogle

benogle commented Jun 17, 2014

Copy link
Copy Markdown
Contributor Author

@nathansobo there is one test failure, and it looks like something you had in there. I probably removed whatever code was handling this, but I dont understand what this is supposed to do or how to repro.

https://janky.githubapp.com/1422287/output

 EditorComponent
   selection rendering
     it does not render empty selections unless they are the first selection (to prevent a Chromium rendering artifact caused by removing it)
       Expected 2 to be 1. (spec/editor-component-spec.coffee:719:58)

@benogle benogle self-assigned this Jun 17, 2014
@probablycorey probablycorey mentioned this pull request Jun 17, 2014
34 of 35 tasks
@benogle benogle changed the title WIP Add highlights Add highlight decorations Jun 17, 2014
Nathan Sobo and others added 6 commits June 17, 2014 14:31
And rename local variable to highlightDecorations to clarify intent
Also rename local variable to lineDecorations for clarity
Using the marker's id plus the decoration class can cause an error in
the event we apply a decoration with the same class twice to the same
marker. This is admittedly unlikely, but I think it's cleaner to just
allocate unique id's for decoration objects.
benogle added a commit that referenced this pull request Jun 18, 2014
@benogle
benogle merged commit e89e214 into master Jun 18, 2014
@nathansobo

Copy link
Copy Markdown
Contributor

👯

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants