Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/input.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class Input extends HTMLElement
@setMode('search')
@editorElement.focus()

focusWord: ->
@focus()
@setMode('searchword')
@setMode('jump')


resetLabelCharChoice: ->
@labelChar = ''

Expand Down
17 changes: 16 additions & 1 deletion lib/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
_ = require 'underscore-plus'
{
getVisibleEditors
decorateRanges,
decorateRanges
getLabelChars
getRangesForWord
getRangesForText
} = require './utils'

Expand All @@ -27,6 +28,9 @@ module.exports =
@subscribe atom.commands.add 'atom-text-editor',
'smalls:start': => @input.focus()

@subscribe atom.commands.add 'atom-text-editor',
'smalls:jump-word': => @input.focusWord()

@subscribe @input.onDidChooseLabel ({labelChar}) =>
@landOrUpdateLabelCharForLabels(labelChar)

Expand All @@ -41,6 +45,10 @@ module.exports =
when 'search'
@input.resetLabelCharChoice()
@clearLabels()
when 'searchword'
@input.resetLabelCharChoice()
@clearLabels()
@searchWord()
when 'jump'
@showLabels()

Expand Down Expand Up @@ -75,6 +83,13 @@ module.exports =
if markers.length
@markersByEditor.set(editor, markers)

searchWord: ->
@clearAllMarkers()
for editor in getVisibleEditors()
markers = decorateRanges(editor, getRangesForWord(editor))
if markers.length
@markersByEditor.set(editor, markers)

showLabels: ->
labels = []
@markersByEditor.forEach (markers, editor) ->
Expand Down
6 changes: 6 additions & 0 deletions lib/utils.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{Range} = require 'atom'
_ = require 'underscore-plus'

smallsWordsPattern = new RegExp (atom.config.get("smalls.jumpWordPattern")), 'g'

getVisibleEditorRange = (editor) ->
[startRow, endRow] = editor.element.getVisibleRowRange()
return null unless (startRow? and endRow?)
Expand All @@ -11,6 +13,9 @@ getVisibleEditorRange = (editor) ->
getRangesForText = (editor, text) ->
getRangesForRegExp(editor, ///#{_.escapeRegExp(text)}///ig)

getRangesForWord = (editor) ->
getRangesForRegExp(editor, smallsWordsPattern)

getRangesForRegExp = (editor, pattern) ->
ranges = []
scanRange = getVisibleEditorRange(editor)
Expand Down Expand Up @@ -72,6 +77,7 @@ getLabelChars = ({amount, chars}) ->

module.exports = {
getRangesForText
getRangesForWord
getRangesForRegExp
decorateRanges
ElementBuilder
Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"description": "Rapid cursor positioning across any visible chars with search and jump.",
"activationCommands": {
"atom-workspace": [
"smalls:start"
"smalls:start",
"smalls:jump-word"
]
},
"keywords": [],
Expand Down Expand Up @@ -40,6 +41,12 @@
"default": 0,
"description": "0 means disable. If input exceed this length, automatically start jump mode"
},
"jumpWordPattern": {
"order": 4,
"type": "string",
"default": "([A-Z]+([0-9a-z])*)|[a-z0-9]{2,}",
"description": "Regular expression to label anchors for word boundary jump"
},
"flashOnLand": {
"order": 32,
"type": "boolean",
Expand Down
27 changes: 7 additions & 20 deletions styles/main.less
Original file line number Diff line number Diff line change
@@ -1,41 +1,28 @@
@import "ui-variables";
@import "syntax-variables";

.smalls.round-box {
box-sizing: border-box;
border-radius: @component-border-radius;
}

@color-error-lighten: lighten(@background-color-error, 30%);

@smalls-label-color: hsl( hue( @text-color-warning ), 100% - saturation( @base-background-color ), 60% - lightness( @app-background-color ) * 0.2 );
atom-text-editor, atom-text-editor::shadow {
.smalls-label {
.smalls.round-box;
// border: 1px solid contrast(@background-color-info);
// color: contrast(@background-color-info);
// background-color: @background-color-info;
// box-shadow: 0 0 2px contrast(@background-color-info);

z-index : 1;
color : @smalls-label-color;
margin-top: -1.5rem;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

To perfectly overlay labels on text, the value of margin-top: -1.5rem; needs to be slightly tuned for different font and font-size. Do you have any better idea to do this?

background-color: @base-background-color;
border: 1px solid @syntax-text-color;
box-shadow: 0 0 3px @syntax-text-color;

padding-left: 0.2em;
padding-right: 0.2em;
margin-left: -0.1em;
margin-top: -1.25em;
position: absolute;
vertical-align: bottom;

text-align: center;
&.not-final {
color: contrast(@color-error-lighten);
background-color: @color-error-lighten;
}
.decided {
text-decoration: line-through;
color: fadeout(@smalls-label-color, 70%);
}
}
.smalls-candidate .region {
.smalls.round-box;
border: 1px solid fadeout(@syntax-result-marker-color, 70%);
background-color: @syntax-selection-color;
}
Expand Down