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

Commit

Permalink
Bugfix/fix welcome buffer layer (#2522)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
akinsho authored Aug 28, 2018
1 parent e482ae8 commit e612eb8
Show file tree
Hide file tree
Showing 21 changed files with 1,099 additions and 402 deletions.
28 changes: 16 additions & 12 deletions browser/src/Editor/BufferManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,25 +338,29 @@ export class Buffer implements IBuffer {
public handleInput(key: string): boolean {
const state = this._store.getState()

const layers: IBufferLayer[] = state.layers[this._id]
const bufferLayers: IBufferLayer[] = state.layers[this._id]

if (!layers || !layers.length) {
if (!bufferLayers || !bufferLayers.length) {
return false
}

const result = layers.reduce<boolean>((prev, curr) => {
if (prev) {
return true
}
const layerShouldHandleInput = bufferLayers.reduce<boolean>(
(layerHandlerExists, currentLayer) => {
if (layerHandlerExists) {
return true
}

if (!curr || !curr.handleInput) {
if (!currentLayer || !currentLayer.handleInput) {
return false
} else if (currentLayer.isActive && currentLayer.isActive()) {
return currentLayer.handleInput(key)
}
return false
} else {
return curr.handleInput(key)
}
}, false)
},
false,
)

return result
return layerShouldHandleInput
}
public async updateHighlights(
tokenColors: TokenColor[],
Expand Down
1 change: 1 addition & 0 deletions browser/src/Editor/NeovimEditor/BufferLayerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type BufferFilter = (buf: Oni.Buffer) => boolean

export interface IBufferLayer extends Oni.BufferLayer {
handleInput?: (key: string) => boolean
isActive?: () => boolean
}

export const createBufferFilterFromLanguage = (language: string) => (buf: Oni.Buffer): boolean => {
Expand Down
8 changes: 5 additions & 3 deletions browser/src/Editor/NeovimEditor/HoverRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import * as React from "react"
import * as types from "vscode-languageserver-types"

import getTokens from "./../../Services/SyntaxHighlighting/TokenGenerator"
import { enableMouse } from "./../../UI/components/common"
import styled, { enableMouse } from "./../../UI/components/common"
import { ErrorInfo } from "./../../UI/components/ErrorInfo"
import { QuickInfoElement, QuickInfoWrapper } from "./../../UI/components/QuickInfo"
import { QuickInfoElement } from "./../../UI/components/QuickInfo"
import QuickInfoWithTheme from "./../../UI/components/QuickInfoContainer"

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

const HoverToolTipId = "hover-tool-tip"

const HoverRendererContainer = QuickInfoWrapper.extend`
const HoverRendererContainer = styled.div`
user-select: none;
cursor: default;
${enableMouse};
`

Expand Down
28 changes: 18 additions & 10 deletions browser/src/Editor/NeovimEditor/NeovimEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import { Workspace } from "./../../Services/Workspace"

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

import { BufferManager, IBuffer } from "./../BufferManager"
import { BufferManager } from "./../BufferManager"
import { CompletionMenu } from "./CompletionMenu"
import { HoverRenderer } from "./HoverRenderer"
import { NeovimPopupMenu } from "./NeovimPopupMenu"
Expand All @@ -94,8 +94,6 @@ import CommandLine from "./../../UI/components/CommandLine"
import ExternalMenus from "./../../UI/components/ExternalMenus"
import WildMenu from "./../../UI/components/WildMenu"

import { WelcomeBufferLayer } from "./WelcomeBufferLayer"

import { CanvasRenderer } from "../../Renderer/CanvasRenderer"
import { WebGLRenderer } from "../../Renderer/WebGL/WebGLRenderer"
import { getInstance as getNotificationsInstance } from "./../../Services/Notifications"
Expand Down Expand Up @@ -148,6 +146,7 @@ export class NeovimEditor extends Editor implements Oni.Editor {
private _bufferLayerManager = getLayerManagerInstance()
private _screenWithPredictions: ScreenWithPredictions

private _onShowWelcomeScreen = new Event<void>()
private _onNeovimQuit: Event<void> = new Event<void>()

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

public get onShowWelcomeScreen() {
return this._onShowWelcomeScreen
}

public get /* override */ activeBuffer(): Oni.Buffer {
return this._bufferManager.getBufferById(this._lastBufferId)
}
Expand Down Expand Up @@ -309,7 +312,7 @@ export class NeovimEditor extends Editor implements Oni.Editor {

// Services
const onColorsChanged = () => {
const updatedColors: any = this._colors.getColors()
const updatedColors = this._colors.getColors()
this._actions.setColors(updatedColors)
}

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

public async createWelcomeBuffer() {
const buf = await this.openFile("WELCOME")
await buf.setScratchBuffer()
return buf
}

public async clearSelection(): Promise<void> {
await this._neovimInstance.input("<esc>")
await this._neovimInstance.input("a")
Expand Down Expand Up @@ -1034,8 +1043,7 @@ export class NeovimEditor extends Editor implements Oni.Editor {
await this.openFiles(filesToOpen, { openMode: Oni.FileOpenMode.Edit })
} else {
if (this._configuration.getValue("experimental.welcome.enabled")) {
const buf = await this.openFile("WELCOME")
buf.addLayer(new WelcomeBufferLayer())
this._onShowWelcomeScreen.dispatch()
}
}

Expand Down Expand Up @@ -1100,8 +1108,8 @@ export class NeovimEditor extends Editor implements Oni.Editor {
<Provider store={this._store}>
<NeovimSurface
onFileDrop={this._onFilesDropped}
autoFocus={this._autoFocus}
renderer={this._renderer}
autoFocus={this._autoFocus}
typingPrediction={this._typingPredictionManager}
neovimInstance={this._neovimInstance}
screen={this._screen}
Expand All @@ -1126,10 +1134,10 @@ export class NeovimEditor extends Editor implements Oni.Editor {
}

// Check if any of the buffer layers can handle the input...
const buf: IBuffer = this.activeBuffer as IBuffer
const result = buf && buf.handleInput(key)
const buf = this.activeBuffer
const layerInputHandler = buf && buf.handleInput(key)

if (result) {
if (layerInputHandler) {
return
}

Expand Down
2 changes: 1 addition & 1 deletion browser/src/Editor/NeovimEditor/NeovimSurface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class NeovimSurface extends React.Component<INeovimSurfaceProps> {
screen={this.props.screen}
/>
</div>
<StackLayer zIndex={2}>
<StackLayer>

This comment has been minimized.

Copy link
@kifirkin

kifirkin Dec 20, 2018

This change introduced tutorial issues described here #2688

<Cursor typingPrediction={this.props.typingPrediction} />
<CursorLine lineType={"line"} />
<CursorLine lineType={"column"} />
Expand Down
Loading

0 comments on commit e612eb8

Please sign in to comment.