Skip to content
This repository was archived by the owner on Apr 1, 2020. It is now read-only.

Commit e612eb8

Browse files
authored
Bugfix/fix welcome buffer layer (#2522)
This PR will fix #1413 and #1459 it uses the handle input method on the buffer layers to define a custom input handler for the welcome layer which is fairly simple i.e. `j` and `k` for navigation and `<enter>` to select, this PR also adds a method to the oni api called `getActiveSection` which returns a string representing the active section of the editor e.g. the particular sidebar element or the menu or commandline Outstanding - [x] Hide cursor when welcome is active - [x] Fix welcome commands (some...) - [x] Allow `enter` key passthrough - [x] Add tests ~add sessions to welcome screen~ leave for another PR
1 parent e482ae8 commit e612eb8

21 files changed

+1099
-402
lines changed

browser/src/Editor/BufferManager.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -338,25 +338,29 @@ export class Buffer implements IBuffer {
338338
public handleInput(key: string): boolean {
339339
const state = this._store.getState()
340340

341-
const layers: IBufferLayer[] = state.layers[this._id]
341+
const bufferLayers: IBufferLayer[] = state.layers[this._id]
342342

343-
if (!layers || !layers.length) {
343+
if (!bufferLayers || !bufferLayers.length) {
344344
return false
345345
}
346346

347-
const result = layers.reduce<boolean>((prev, curr) => {
348-
if (prev) {
349-
return true
350-
}
347+
const layerShouldHandleInput = bufferLayers.reduce<boolean>(
348+
(layerHandlerExists, currentLayer) => {
349+
if (layerHandlerExists) {
350+
return true
351+
}
351352

352-
if (!curr || !curr.handleInput) {
353+
if (!currentLayer || !currentLayer.handleInput) {
354+
return false
355+
} else if (currentLayer.isActive && currentLayer.isActive()) {
356+
return currentLayer.handleInput(key)
357+
}
353358
return false
354-
} else {
355-
return curr.handleInput(key)
356-
}
357-
}, false)
359+
},
360+
false,
361+
)
358362

359-
return result
363+
return layerShouldHandleInput
360364
}
361365
public async updateHighlights(
362366
tokenColors: TokenColor[],

browser/src/Editor/NeovimEditor/BufferLayerManager.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type BufferFilter = (buf: Oni.Buffer) => boolean
1111

1212
export interface IBufferLayer extends Oni.BufferLayer {
1313
handleInput?: (key: string) => boolean
14+
isActive?: () => boolean
1415
}
1516

1617
export const createBufferFilterFromLanguage = (language: string) => (buf: Oni.Buffer): boolean => {

browser/src/Editor/NeovimEditor/HoverRenderer.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import * as React from "react"
88
import * as types from "vscode-languageserver-types"
99

1010
import getTokens from "./../../Services/SyntaxHighlighting/TokenGenerator"
11-
import { enableMouse } from "./../../UI/components/common"
11+
import styled, { enableMouse } from "./../../UI/components/common"
1212
import { ErrorInfo } from "./../../UI/components/ErrorInfo"
13-
import { QuickInfoElement, QuickInfoWrapper } from "./../../UI/components/QuickInfo"
13+
import { QuickInfoElement } from "./../../UI/components/QuickInfo"
1414
import QuickInfoWithTheme from "./../../UI/components/QuickInfoContainer"
1515

1616
import * as Helpers from "./../../Plugins/Api/LanguageClient/LanguageClientHelpers"
@@ -22,7 +22,9 @@ import { IToolTipsProvider } from "./ToolTipsProvider"
2222

2323
const HoverToolTipId = "hover-tool-tip"
2424

25-
const HoverRendererContainer = QuickInfoWrapper.extend`
25+
const HoverRendererContainer = styled.div`
26+
user-select: none;
27+
cursor: default;
2628
${enableMouse};
2729
`
2830

browser/src/Editor/NeovimEditor/NeovimEditor.tsx

+18-10
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import { Workspace } from "./../../Services/Workspace"
6969

7070
import { Editor } from "./../Editor"
7171

72-
import { BufferManager, IBuffer } from "./../BufferManager"
72+
import { BufferManager } from "./../BufferManager"
7373
import { CompletionMenu } from "./CompletionMenu"
7474
import { HoverRenderer } from "./HoverRenderer"
7575
import { NeovimPopupMenu } from "./NeovimPopupMenu"
@@ -94,8 +94,6 @@ import CommandLine from "./../../UI/components/CommandLine"
9494
import ExternalMenus from "./../../UI/components/ExternalMenus"
9595
import WildMenu from "./../../UI/components/WildMenu"
9696

97-
import { WelcomeBufferLayer } from "./WelcomeBufferLayer"
98-
9997
import { CanvasRenderer } from "../../Renderer/CanvasRenderer"
10098
import { WebGLRenderer } from "../../Renderer/WebGL/WebGLRenderer"
10199
import { getInstance as getNotificationsInstance } from "./../../Services/Notifications"
@@ -148,6 +146,7 @@ export class NeovimEditor extends Editor implements Oni.Editor {
148146
private _bufferLayerManager = getLayerManagerInstance()
149147
private _screenWithPredictions: ScreenWithPredictions
150148

149+
private _onShowWelcomeScreen = new Event<void>()
151150
private _onNeovimQuit: Event<void> = new Event<void>()
152151

153152
private _autoFocus: boolean = true
@@ -156,6 +155,10 @@ export class NeovimEditor extends Editor implements Oni.Editor {
156155
return this._onNeovimQuit
157156
}
158157

158+
public get onShowWelcomeScreen() {
159+
return this._onShowWelcomeScreen
160+
}
161+
159162
public get /* override */ activeBuffer(): Oni.Buffer {
160163
return this._bufferManager.getBufferById(this._lastBufferId)
161164
}
@@ -309,7 +312,7 @@ export class NeovimEditor extends Editor implements Oni.Editor {
309312

310313
// Services
311314
const onColorsChanged = () => {
312-
const updatedColors: any = this._colors.getColors()
315+
const updatedColors = this._colors.getColors()
313316
this._actions.setColors(updatedColors)
314317
}
315318

@@ -834,6 +837,12 @@ export class NeovimEditor extends Editor implements Oni.Editor {
834837
this._neovimInstance.autoCommands.executeAutoCommand("FocusLost")
835838
}
836839

840+
public async createWelcomeBuffer() {
841+
const buf = await this.openFile("WELCOME")
842+
await buf.setScratchBuffer()
843+
return buf
844+
}
845+
837846
public async clearSelection(): Promise<void> {
838847
await this._neovimInstance.input("<esc>")
839848
await this._neovimInstance.input("a")
@@ -1034,8 +1043,7 @@ export class NeovimEditor extends Editor implements Oni.Editor {
10341043
await this.openFiles(filesToOpen, { openMode: Oni.FileOpenMode.Edit })
10351044
} else {
10361045
if (this._configuration.getValue("experimental.welcome.enabled")) {
1037-
const buf = await this.openFile("WELCOME")
1038-
buf.addLayer(new WelcomeBufferLayer())
1046+
this._onShowWelcomeScreen.dispatch()
10391047
}
10401048
}
10411049

@@ -1100,8 +1108,8 @@ export class NeovimEditor extends Editor implements Oni.Editor {
11001108
<Provider store={this._store}>
11011109
<NeovimSurface
11021110
onFileDrop={this._onFilesDropped}
1103-
autoFocus={this._autoFocus}
11041111
renderer={this._renderer}
1112+
autoFocus={this._autoFocus}
11051113
typingPrediction={this._typingPredictionManager}
11061114
neovimInstance={this._neovimInstance}
11071115
screen={this._screen}
@@ -1126,10 +1134,10 @@ export class NeovimEditor extends Editor implements Oni.Editor {
11261134
}
11271135

11281136
// Check if any of the buffer layers can handle the input...
1129-
const buf: IBuffer = this.activeBuffer as IBuffer
1130-
const result = buf && buf.handleInput(key)
1137+
const buf = this.activeBuffer
1138+
const layerInputHandler = buf && buf.handleInput(key)
11311139

1132-
if (result) {
1140+
if (layerInputHandler) {
11331141
return
11341142
}
11351143

browser/src/Editor/NeovimEditor/NeovimSurface.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class NeovimSurface extends React.Component<INeovimSurfaceProps> {
8787
screen={this.props.screen}
8888
/>
8989
</div>
90-
<StackLayer zIndex={2}>
90+
<StackLayer>
9191
<Cursor typingPrediction={this.props.typingPrediction} />
9292
<CursorLine lineType={"line"} />
9393
<CursorLine lineType={"column"} />

0 commit comments

Comments
 (0)