Clip cursor width when soft-wrap is on and cursor is at the end of line

This prevents the parent tile from disabling sub-pixel anti-aliasing.
For some reason, adding `overflow: hidden` to the cursor container
element doesn't solve the issue, so we're adding this workaround
instead.
This commit is contained in:
Antonio Scandurra
2018-03-13 12:04:15 +01:00
parent 3727c93965
commit 26837d65b4
2 changed files with 12 additions and 1 deletions

View File

@@ -564,9 +564,20 @@ describe('TextEditorComponent', () => {
it('gives cursors at the end of lines the width of an "x" character', async () => {
const {component, element, editor} = buildComponent()
editor.setText('abcde')
await setEditorWidthInCharacters(component, 5.5)
editor.setCursorScreenPosition([0, Infinity])
await component.getNextUpdatePromise()
expect(element.querySelector('.cursor').offsetWidth).toBe(Math.round(component.getBaseCharacterWidth()))
// Clip cursor width when soft-wrap is on and the cursor is at the end of
// the line. This prevents the parent tile from disabling sub-pixel
// anti-aliasing. For some reason, adding overflow: hidden to the cursor
// container doesn't solve this issue so we're adding this workaround instead.
editor.setSoftWrapped(true)
await component.getNextUpdatePromise()
expect(element.querySelector('.cursor').offsetWidth).toBeLessThan(Math.round(component.getBaseCharacterWidth()))
})
it('positions and sizes cursors correctly when they are located next to a fold marker', async () => {

View File

@@ -3522,7 +3522,7 @@ class CursorsAndInputComponent {
const cursorStyle = {
height: cursorHeight,
width: pixelWidth + 'px',
width: Math.min(pixelWidth, scrollWidth - pixelLeft) + 'px',
transform: `translate(${pixelLeft}px, ${pixelTop}px)`
}
if (extraCursorStyle) Object.assign(cursorStyle, extraCursorStyle)