Skip to content

Commit

Permalink
fix: fix selection opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Feb 25, 2020
1 parent abffb51 commit 660ecc9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,34 @@ class XTerminalElementImpl extends HTMLElement {
const root = getComputedStyle(document.documentElement)
colors.background = root.getPropertyValue('--standard-app-background-color')
colors.foreground = root.getPropertyValue('--standard-text-color')
colors.selection = root.getPropertyValue('--standard-background-color-selected')
colors.cursor = root.getPropertyValue('--standard-text-color-highlight')
break
}
}

if (!this.model.profile.webgl) {
colors.selection = this.setMaximumOpacity(colors.selection, 0.5)
}

return colors
}

setMaximumOpacity (color, opacity) {
// modified from https://stackoverflow.com/a/24390910/806777
const cvs = document.createElement('canvas')
cvs.height = 1
cvs.width = 1
const ctx = cvs.getContext('2d')
ctx.fillStyle = color
ctx.fillRect(0, 0, 1, 1)
const [r, g, b, a] = ctx.getImageData(0, 0, 1, 1).data
if (a / 255 <= opacity) {
return color
}
return `rgba(${r}, ${g}, ${b}, ${opacity})`
}

getXtermOptions () {
let xtermOptions = {
cursorBlink: true,
Expand Down
1 change: 1 addition & 0 deletions styles/x-terminal.less
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
:root {
--standard-app-background-color: @app-background-color;
--standard-text-color: @text-color;
--standard-background-color-selected: @background-color-selected;
--standard-text-color-highlight: @text-color-highlight;
}

Expand Down

0 comments on commit 660ecc9

Please sign in to comment.