Merge branch 'master' into work (bugfixes)

cpsdqs/unified-input
Ondřej Hruška 7 years ago
commit bb76f87b13
  1. 15
      js/term_screen.js
  2. 2
      sass/pages/_term.scss

@ -184,20 +184,20 @@ window.TermScreen = class TermScreen {
let selectStart = (x, y) => { let selectStart = (x, y) => {
if (selecting) return if (selecting) return
selecting = true selecting = true
this.selection.start = this.selection.end = this.screenToGrid(x, y) this.selection.start = this.selection.end = this.screenToGrid(x, y, true)
this.scheduleDraw('select-start') this.scheduleDraw('select-start')
} }
let selectMove = (x, y) => { let selectMove = (x, y) => {
if (!selecting) return if (!selecting) return
this.selection.end = this.screenToGrid(x, y) this.selection.end = this.screenToGrid(x, y, true)
this.scheduleDraw('select-move') this.scheduleDraw('select-move')
} }
let selectEnd = (x, y) => { let selectEnd = (x, y) => {
if (!selecting) return if (!selecting) return
selecting = false selecting = false
this.selection.end = this.screenToGrid(x, y) this.selection.end = this.screenToGrid(x, y, true)
this.scheduleDraw('select-end') this.scheduleDraw('select-end')
Object.assign(this.selection, this.getNormalizedSelection()) Object.assign(this.selection, this.getNormalizedSelection())
} }
@ -710,13 +710,14 @@ window.TermScreen = class TermScreen {
* Converts screen coordinates to grid coordinates. * Converts screen coordinates to grid coordinates.
* @param {number} x - x in pixels * @param {number} x - x in pixels
* @param {number} y - y in pixels * @param {number} y - y in pixels
* @param {boolean} rounded - whether to round the coord, used for select highlighting
* @returns {number[]} a tuple of (x, y) in cells * @returns {number[]} a tuple of (x, y) in cells
*/ */
screenToGrid (x, y) { screenToGrid (x, y, rounded = false) {
let cellSize = this.getCellSize() let cellSize = this.getCellSize()
return [ return [
Math.floor((x + cellSize.width / 2) / cellSize.width), Math.floor((x + (rounded ? cellSize.width / 2 : 0)) / cellSize.width),
Math.floor(y / cellSize.height) Math.floor(y / cellSize.height)
] ]
} }
@ -1119,8 +1120,8 @@ window.TermScreen = class TermScreen {
} }
this.input.setMouseMode(trackMouseClicks, trackMouseMovement) this.input.setMouseMode(trackMouseClicks, trackMouseMovement)
this.selection.selectable = !trackMouseMovement this.selection.selectable = !trackMouseClicks && !trackMouseMovement
$(this.canvas).toggleClass('selectable', !trackMouseMovement) $(this.canvas).toggleClass('selectable', this.selection.selectable)
this.mouseMode = { this.mouseMode = {
clicks: trackMouseClicks, clicks: trackMouseClicks,
movement: trackMouseMovement movement: trackMouseMovement

@ -24,6 +24,8 @@ body.term {
position: relative; position: relative;
line-height: 0; line-height: 0;
cursor: default;
canvas.selectable { canvas.selectable {
cursor: text; cursor: text;
} }

Loading…
Cancel
Save