Skip to content

Add crosshair cursor and or logic options #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,24 @@ Default key combinations are:
The modifier key and mouse button can both be configured from the package's settings page. Available options:

### Mouse Button
- Left
- Left (default)
- Middle
- Right

### Key Trigger
- Shift
- Alt/Option
### Key Trigger (default selected based on platform)
- Shift (default on linux)
- Alt/Option (default on win/mac)
- Ctrl
- None

To use middle mouse selection working since version 1.4.0 please use the following settings.
You can require both a certain key & modifier, or trigger on either one.

![](https://cloud.githubusercontent.com/assets/633193/12469581/e829bcd0-c027-11e5-8104-901fc0ff4a73.png)
### Logic Operator
- And (default)
- Or

Optionally change cursor to crosshair when selecting.

### Change Cursor to Crosshair
- true
- false (default)
16 changes: 12 additions & 4 deletions lib/editor-handler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ module.exports =
e.preventDefault()
return false

if @_mainMouseAndKeyDown(e)
if @_mainMouseAndOrKeyDown(e)
@_resetState()
if @inputCfg.cursorToCrosshair
@editorElement.shadowRoot.querySelector(
'.lines').style.cursor = 'crosshair'
@mouseStartPos = @_screenPositionForMouseEvent(e)
@mouseEndPos = @mouseStartPos
e.preventDefault()
Expand All @@ -48,7 +51,7 @@ module.exports =
onMouseMove: (e) =>
if @mouseStartPos
e.preventDefault()
if @_mainMouseDown(e)
if @_mainMouseAndOrKeyDown(e)
@mouseEndPos = @_screenPositionForMouseEvent(e)
return if @mouseEndPos.isEqual @mouseEndPosPrev
@_selectBoxAroundCursors()
Expand Down Expand Up @@ -76,6 +79,9 @@ module.exports =
# -------

_resetState: ->
if @inputCfg.cursorToCrosshair
@editorElement?.shadowRoot.querySelector(
'.lines').style.cursor = ''
@mouseStartPos = null
@mouseEndPos = null

Expand All @@ -101,8 +107,10 @@ module.exports =
_mainMouseDown: (e) ->
e.which is @inputCfg.mouseNum

_mainMouseAndKeyDown: (e) ->
if @inputCfg.selectKey
_mainMouseAndOrKeyDown: (e) ->
if @inputCfg.selectKey && (@inputCfg.mouseKeyLogicOperator == "Or")
@_mainMouseDown(e) or e[@inputCfg.selectKey]
else if @inputCfg.selectKey
@_mainMouseDown(e) and e[@inputCfg.selectKey]
else
@_mainMouseDown(e)
Expand Down
21 changes: 21 additions & 0 deletions lib/sublime-select.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ inputCfg = defaultCfg
module.exports =

config:
cursorToCrosshair:
title: "Change Cursor to Crosshair"
description: "The mouse cursor will change to crosshair during column selection.
IF empty, the default will be used \"false\"."
type:'boolean'
default: false

mouseButtonTrigger:
title: "Mouse Button"
description: "The mouse button that will trigger column selection.
Expand All @@ -52,6 +59,14 @@ module.exports =
enum: (key for key, value of mouseNumMap)
default: defaultCfg.mouseName

mouseKeyLogicOperator:
title: "Logic Operator"
description: "Should BOTH/EITHER \"Mouse Button\" And/Or \"Key\" trigger column selection?
If empty or \"Select Key\" is set to empty or none, the default will be used \"And\"."
type: 'string',
enum: ['And','Or']
default: 'And'

selectKeyTrigger:
title: "Select Key"
description: "The key that will trigger column selection.
Expand All @@ -64,10 +79,16 @@ module.exports =
@observers = []
@editor_handler = null

@observers.push atom.config.observe "#{packageName}.cursorToCrosshair", (newValue) =>
inputCfg.cursorToCrosshair = newValue

@observers.push atom.config.observe "#{packageName}.mouseButtonTrigger", (newValue) =>
inputCfg.mouseName = newValue
inputCfg.mouseNum = mouseNumMap[newValue]

@observers.push atom.config.observe "#{packageName}.mouseKeyLogicOperator", (newValue) =>
inputCfg.mouseKeyLogicOperator = newValue

@observers.push atom.config.observe "#{packageName}.selectKeyTrigger", (newValue) =>
inputCfg.selectKeyName = newValue
inputCfg.selectKey = selectKeyMap[newValue]
Expand Down