mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-11 04:48:44 +03:00
Add getLineNumbersForClass()
Also clean up and use klass
This commit is contained in:
parent
964e88f131
commit
1ff97fc21a
@ -1900,7 +1900,7 @@ describe "Editor", ->
|
||||
expect($(element)).toHaveClass('line-number-3')
|
||||
|
||||
it "returns falsy when there is no line element", ->
|
||||
expect(editor.gutter.getLineNumberElement(42)).toBeFalsy()
|
||||
expect(editor.gutter.getLineNumberElement(42).length).toBeFalsy()
|
||||
|
||||
it "can add and remove classes to all the line numbers", ->
|
||||
elements = editor.gutter.addClassToAllLines('heyok')
|
||||
@ -1916,6 +1916,19 @@ describe "Editor", ->
|
||||
element = editor.gutter.getLineNumberElement(2)
|
||||
expect($(element)).not.toHaveClass('heyok')
|
||||
|
||||
it "can fetch line numbers by their class", ->
|
||||
editor.gutter.addClassToLine(1, 'heyok')
|
||||
editor.gutter.addClassToLine(3, 'heyok')
|
||||
|
||||
elements = editor.gutter.getLineNumberElementsForClass('heyok')
|
||||
expect(elements.length).toBe 2
|
||||
|
||||
expect($(elements[0])).toHaveClass 'line-number-1'
|
||||
expect($(elements[0])).toHaveClass 'heyok'
|
||||
|
||||
expect($(elements[1])).toHaveClass 'line-number-3'
|
||||
expect($(elements[1])).toHaveClass 'heyok'
|
||||
|
||||
describe "gutter line highlighting", ->
|
||||
beforeEach ->
|
||||
editor.attachToDom(heightInLines: 5.5)
|
||||
|
@ -66,51 +66,57 @@ class Gutter extends View
|
||||
#
|
||||
# Returns a list of {HTMLElement}s.
|
||||
getLineNumberElements: ->
|
||||
@lineNumbers[0].getElementsByClassName('line-number')
|
||||
@lineNumbers[0].childNodes
|
||||
|
||||
# Get all the line-number divs.
|
||||
#
|
||||
# Returns a list of {HTMLElement}s.
|
||||
getLineNumberElementsForClass: (klass) ->
|
||||
@lineNumbers[0].getElementsByClassName(klass)
|
||||
|
||||
# Get a single line-number div.
|
||||
#
|
||||
# * lineNumber: 0 based line number
|
||||
# * bufferRow: 0 based line number
|
||||
#
|
||||
# Returns a {HTMLElement}
|
||||
getLineNumberElement: (lineNumber) ->
|
||||
@lineNumbers[0].getElementsByClassName("line-number-#{lineNumber}")[0]
|
||||
# Returns a list of {HTMLElement}s that correspond to the bufferRow
|
||||
getLineNumberElement: (bufferRow) ->
|
||||
@getLineNumberElementsForClass("line-number-#{bufferRow}")
|
||||
|
||||
# Add a class to all line-number divs.
|
||||
#
|
||||
# * clas: string class name
|
||||
# * klass: string class name
|
||||
#
|
||||
# Returns a list of {HTMLElement}s.
|
||||
addClassToAllLines: (clas)->
|
||||
$.fn.addClass.call(@getLineNumberElements(), clas)
|
||||
addClassToAllLines: (klass)->
|
||||
$.fn.addClass.call(@getLineNumberElements(), klass)
|
||||
|
||||
# Remove a class from all line-number divs.
|
||||
#
|
||||
# * clas: string class name
|
||||
# * klass: string class name
|
||||
#
|
||||
# Returns a list of {HTMLElement}s.
|
||||
removeClassFromAllLines: (clas)->
|
||||
$.fn.removeClass.call(@getLineNumberElements(), clas)
|
||||
removeClassFromAllLines: (klass)->
|
||||
$.fn.removeClass.call(@getLineNumberElements(), klass)
|
||||
|
||||
# Add a class to a single line-number div
|
||||
#
|
||||
# * lineNumber: 0 based line number
|
||||
# * clas: string class name
|
||||
# * bufferRow: 0 based line number
|
||||
# * klass: string class name
|
||||
#
|
||||
# Returns the {HTMLElement} on which the class was set. undefined if the line was not found
|
||||
addClassToLine: (lineNumber, clas)->
|
||||
line = @lineNumbers[0].getElementsByClassName("line-number-#{lineNumber}")
|
||||
$.fn.addClass.call(line, clas) if line
|
||||
addClassToLine: (bufferRow, klass)->
|
||||
line = @getLineNumberElement(bufferRow)
|
||||
$.fn.addClass.call(line, klass) if line and line.length
|
||||
|
||||
# Remove a class from a single line-number div
|
||||
#
|
||||
# * lineNumber: 0 based line number
|
||||
# * clas: string class name
|
||||
# * bufferRow: 0 based line number
|
||||
# * klass: string class name
|
||||
#
|
||||
# Returns the {HTMLElement} on which the class was set. undefined if the line was not found
|
||||
removeClassFromLine: (lineNumber, clas)->
|
||||
line = @lineNumbers[0].getElementsByClassName("line-number-#{lineNumber}")
|
||||
$.fn.removeClass.call(line, clas) if line
|
||||
removeClassFromLine: (bufferRow, klass)->
|
||||
line = @getLineNumberElement(bufferRow)
|
||||
$.fn.removeClass.call(line, klass) if line and line.length
|
||||
|
||||
### Internal ###
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user