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

Commit

Permalink
Quick Info: Fix issue where quick-info would not be dismissed (#508)
Browse files Browse the repository at this point in the history
* Fix formatting, and handling 'clear-quick-info' event

* Fix missing comma

* Clean up styling for quick info and signature help

* Allow mouse events on quick info

* Fix cursor styling on QuickInfo

* Remove unused padding
  • Loading branch information
extr0py committed Jul 1, 2017
1 parent 6b72b09 commit 31f872c
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 77 deletions.
2 changes: 2 additions & 0 deletions browser/src/Plugins/Api/Oni.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ export class Oni extends EventEmitter implements Oni.Plugin.Api {
info: quickInfo.title,
documentation: quickInfo.description,
})
} else {
this._channel.send("clear-quick-info", originalContext, null)
}
}, (err) => {
this._channel.sendError("show-quick-info", originalContext, err)
Expand Down
146 changes: 74 additions & 72 deletions browser/src/Plugins/PluginManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,80 +158,82 @@ export class PluginManager extends EventEmitter {

// TODO: Refactor these handlers to separate classes
// - pluginManager.registerResponseHandler("show-quick-info", new QuickInfoHandler())

switch (pluginResponse.type) {
case "show-quick-info":
if (!this._validateOriginEventMatchesCurrentEvent(pluginResponse)) {
return
}

if (!pluginResponse.error) {
case "clear-quick-info":
UI.Actions.hideQuickInfo()
setTimeout(() => {
if (!this._validateOriginEventMatchesCurrentEvent(pluginResponse)) {
return
}
UI.Actions.showQuickInfo(pluginResponse.payload.info, pluginResponse.payload.documentation)
}, this._config.getValue("editor.quickInfo.delay"))
} else {
setTimeout(() => UI.Actions.hideQuickInfo())
}
break
case "goto-definition":
if (!this._validateOriginEventMatchesCurrentEvent(pluginResponse)) {
return
}

// TODO: Refactor to 'Service', break remaining NeoVim dependencies
const { filePath, line, column } = pluginResponse.payload
this._neovimInstance.command("e! " + filePath)
this._neovimInstance.command(`cal cursor(${line}, ${column})`)
this._neovimInstance.command("norm zz")
break
case "completion-provider":
if (!this._validateOriginEventMatchesCurrentEvent(pluginResponse)) {
return
}

if (!pluginResponse.payload) {
return
}

setTimeout(() => UI.Actions.showCompletions(pluginResponse.payload))
break
case "completion-provider-item-selected":
setTimeout(() => UI.Actions.setDetailedCompletionEntry(pluginResponse.payload.details))
break
case "set-errors":
this.emit("set-errors", pluginResponse.payload.key, pluginResponse.payload.fileName, pluginResponse.payload.errors, pluginResponse.payload.color)
break
case "find-all-references":
this.emit("find-all-references", pluginResponse.payload.references)
break
case "format":
this.emit("format", pluginResponse.payload)
break
case "execute-shell-command":
// TODO: Check plugin permission
this.emit("execute-shell-command", pluginResponse.payload)
break
case "evaluate-block-result":
this.emit("evaluate-block-result", pluginResponse.payload)
break
case "set-syntax-highlights":
this.emit("set-syntax-highlights", pluginResponse.payload)
break
case "clear-syntax-highlights":
this.emit("clear-syntax-highlights", pluginResponse.payload)
break
case "signature-help-response":
this.emit("signature-help-response", pluginResponse.error, pluginResponse.payload)
break
case "redux-action":
UI.store.dispatch(pluginResponse.payload)
break
default:
this.emit("logWarning", "Unexpected plugin type: " + pluginResponse.type)
break
case "show-quick-info":
if (!this._validateOriginEventMatchesCurrentEvent(pluginResponse)) {
return
}

if (!pluginResponse.error) {
UI.Actions.hideQuickInfo()
setTimeout(() => {
if (!this._validateOriginEventMatchesCurrentEvent(pluginResponse)) {
return
}
UI.Actions.showQuickInfo(pluginResponse.payload.info, pluginResponse.payload.documentation)
}, this._config.getValue("editor.quickInfo.delay"))
} else {
setTimeout(() => UI.Actions.hideQuickInfo())
}
break
case "goto-definition":
if (!this._validateOriginEventMatchesCurrentEvent(pluginResponse)) {
return
}

// TODO: Refactor to 'Service', break remaining NeoVim dependencies
const { filePath, line, column } = pluginResponse.payload
this._neovimInstance.command("e! " + filePath)
this._neovimInstance.command(`cal cursor(${line}, ${column})`)
this._neovimInstance.command("norm zz")
break
case "completion-provider":
if (!this._validateOriginEventMatchesCurrentEvent(pluginResponse)) {
return
}

if (!pluginResponse.payload) {
return
}

setTimeout(() => UI.Actions.showCompletions(pluginResponse.payload))
break
case "completion-provider-item-selected":
setTimeout(() => UI.Actions.setDetailedCompletionEntry(pluginResponse.payload.details))
break
case "set-errors":
this.emit("set-errors", pluginResponse.payload.key, pluginResponse.payload.fileName, pluginResponse.payload.errors, pluginResponse.payload.color)
break
case "find-all-references":
this.emit("find-all-references", pluginResponse.payload.references)
break
case "format":
this.emit("format", pluginResponse.payload)
break
case "execute-shell-command":
// TODO: Check plugin permission
this.emit("execute-shell-command", pluginResponse.payload)
break
case "evaluate-block-result":
this.emit("evaluate-block-result", pluginResponse.payload)
break
case "set-syntax-highlights":
this.emit("set-syntax-highlights", pluginResponse.payload)
break
case "clear-syntax-highlights":
this.emit("clear-syntax-highlights", pluginResponse.payload)
break
case "signature-help-response":
this.emit("signature-help-response", pluginResponse.error, pluginResponse.payload)
break
case "redux-action":
UI.store.dispatch(pluginResponse.payload)
break
default:
this.emit("logWarning", "Unexpected plugin type: " + pluginResponse.type)
}
}

Expand Down
10 changes: 7 additions & 3 deletions browser/src/UI/components/QuickInfo.less
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@
transition: all 0.5s;
animation-name: appear;
animation-duration: 0.5s;
-webkit-user-select: none;
cursor: default;

.quickinfo {
.box-shadow;

background-color: @background-color;
padding: 4px;
color: @text-color;
text-overflow: ellipsis;
overflow: hidden;

.title {
width: 100%;
white-space: nowrap;
margin: 4px;
margin: 8px;
}

.documentation {
margin: 4px;
.box-shadow-inset;
padding: 8px;
color: @text-color-detail;
font-size: @font-size-small;
max-height: 48px;
overflow-y: auto;
}

.selected {
Expand Down
10 changes: 8 additions & 2 deletions browser/src/UI/components/QuickInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class QuickInfo extends React.Component<IQuickInfoProps, void> {

const innerStyle = openFromTop ? openFromTopStyle : openFromBottomStyle

return <div key={"quickinfo-container"} className="quickinfo-container" style={containerStyle}>
return <div key={"quickinfo-container"} className="quickinfo-container enable-mouse" style={containerStyle}>
<div key={"quickInfo"} style={innerStyle} className="quickinfo">
{this.props.elements}
</div>
Expand All @@ -75,6 +75,10 @@ export class QuickInfoTitle extends TextComponent {
export class QuickInfoDocumentation extends TextComponent {
public render(): JSX.Element {

if (!this.props.text) {
return null
}

const lines = this.props.text.split(os.EOL)
const divs = lines.map((l) => <div>{l}</div>)

Expand Down Expand Up @@ -154,10 +158,12 @@ const mapStateToSignatureHelpProps = (state: IState): IQuickInfoProps => {
parameters.splice(i, 0, <Text text={currentItem.separator + " "} />)
}

let elements = [<Text text={currentItem.prefix} />]
let titleContents = [<Text text={currentItem.prefix} />]
.concat(parameters)
.concat([<Text text={currentItem.suffix} />])

let elements = [<div className="title">{titleContents}</div>]

const selectedIndex = Math.min(currentItem.parameters.length, state.signatureHelp.argumentIndex)
const selectedArgument = currentItem.parameters[selectedIndex]
if (selectedArgument && selectedArgument.documentation) {
Expand Down

0 comments on commit 31f872c

Please sign in to comment.