Skip to content

Commit

Permalink
Add stuff and loadingSize stuff which is ugly
Browse files Browse the repository at this point in the history
  • Loading branch information
smolck committed Sep 4, 2021
1 parent 3228db2 commit d3de5a8
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 176 deletions.
6 changes: 4 additions & 2 deletions src/components/extensions/lsp-references.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { RowNormal, RowHeader } from '../row-container'
import { PluginRight } from '../plugin-container'
import { vimBlur, vimFocus } from '../../ui/uikit'
import { vimFocus } from '../../ui/uikit'
import { simplifyPath } from '../../utils'
// TODO(smolck): import { showCursorline } from '../../core/cursor'
import { badgeStyle } from '../../ui/styles'
import { Component } from 'inferno'
import Input from '../text-input'
import { invoke, listen, currentNvimState } from '../../helpers'
import { invoke, currentNvimState } from '../../helpers'
import Cursor from '../../cursor'

export type Reference = {
Expand Down Expand Up @@ -47,6 +47,7 @@ const highlightPattern = (
const WhyDiv = (props: any) => <div {...props}>{props.children}</div>

type Props = {
fontSize: number
cursor: Cursor
visible: boolean
references: Refs[]
Expand Down Expand Up @@ -219,6 +220,7 @@ export default class LspReferences extends Component<
return (
<PluginRight id={'references'} visible={this.state!.visible}>
<Input
loadingSize={this.props.fontSize}
id={'lsp-references-input'}
up={() => this.up()}
hide={() => this.hide()}
Expand Down
5 changes: 2 additions & 3 deletions src/components/loading.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import * as workspace from '../workspace'
import Icon from './icon'

interface LoaderParams {
size?: number
size: number
color?: string
}

export default (
{ color, size = workspace.font.size + 2 } = {} as LoaderParams
{ color, size } = {} as LoaderParams
) => (
<div
style={{
Expand Down
34 changes: 17 additions & 17 deletions src/components/nvim/command-line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ let state = {
type S = typeof state

const CommandLine = ({
loadingSize,
options,
position,
value,
prompt,
visible,
kind,
ix: stateIx,
}: S) => {
}: S & { loadingSize: number }) => {
const maybePrompt = prompt && (
<div
style={{
Expand All @@ -56,6 +57,7 @@ const CommandLine = ({
>
{maybePrompt}
<Input
loadingSize={loadingSize}
id={'command-line-input'}
focus={true}
value={value}
Expand Down Expand Up @@ -87,42 +89,40 @@ plugins?.appendChild(container)

// TODO: use export cns. this component is a high priority so it should be loaded early
// because someone might open cmdline early
export const wildmenuShow = (items: any[]) => {
export const wildmenuShow = (loadingSize: number, items: any[]) => {
state.options = [...new Set(items.map((item) => item.word))]
render(<CommandLine {...state} />, container)
render(<CommandLine {...state} loadingSize={loadingSize} />, container)
}

export const wildmenuSelect = (ix: number) => {
export const wildmenuSelect = (loadingSize: number, ix: number) => {
state.ix = ix
render(<CommandLine {...state} />, container)
render(<CommandLine {...state} loadingSize={loadingSize} />, container)
}

export const wildmenuHide = () => {
export const wildmenuHide = (loadingSize: number) => {
state.options = [...new Set([])]
render(<CommandLine {...state} />, container)
render(<CommandLine {...state} loadingSize={loadingSize} />, container)
}

export const cmdlineHide = () => {
export const cmdlineHide = (loadingSize: number) => {
// TODO(smolck)
document.getElementById('keycomp-textarea')?.focus()

state.visible = false

render(<CommandLine {...state} />, container)
render(<CommandLine {...state} loadingSize={loadingSize} />, container)
}

export const cmdlineUpdate = ({
cmd,
kind,
position,
prompt,
}: CommandUpdate) => {
export const cmdlineUpdate = (
loadingSize: number,
{ cmd, kind, position, prompt }: CommandUpdate
) => {
if (kind) state.kind = kind
if (prompt) state.prompt = prompt
state.position = position
state.visible = true
state.options = cmd ? state.options : []
state.value = is.string(cmd) && state.value !== cmd ? cmd : state.value

render(<CommandLine {...state} />, container)
}
render(<CommandLine {...state} loadingSize={loadingSize} />, container)
}
3 changes: 2 additions & 1 deletion src/components/nvim/message-history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Icon from '../icon'
import { colors } from '../../ui/styles'
import { render } from 'inferno'

export default (cursor: Cursor) => {
export default (loadingSize: number, cursor: Cursor) => {
let state = {
query: '',
messages: [] as Message[],
Expand Down Expand Up @@ -58,6 +58,7 @@ export default (cursor: Cursor) => {
}}
>
<Input
loadingSize={loadingSize}
id={'message-history-input'}
hide={hide}
next={next}
Expand Down
27 changes: 17 additions & 10 deletions src/components/nvim/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ let state = {
value: '',
position: 0,
kind: CommandType.Ex,
hideCb: () => {}
hideCb: () => {},
}

export const setSearchHideCallback = (cb: () => void) => {
state.hideCb = cb
console.warn("search.tsx: TODO(smolck): this is kinda hacky, maybe do something about that")
console.warn(
'search.tsx: TODO(smolck): this is kinda hacky, maybe do something about that'
)
}

type S = typeof state
Expand All @@ -29,7 +31,7 @@ const printCommandType = (kind: CommandType) => {
else return 'search'
}

const VimSearch = ({ visible, kind, value, position, hideCb }: S) => (
const VimSearch = ({ loadingSize, visible, kind, value, position, hideCb }: S & { loadingSize: number }) => (
<div style={{ display: visible ? 'flex' : 'none', flex: 1 }}>
<div
style={{
Expand All @@ -44,6 +46,7 @@ const VimSearch = ({ visible, kind, value, position, hideCb }: S) => (
</div>

<Input
loadingSize={loadingSize}
id={'vim-search-input'}
small={true}
focus={visible}
Expand All @@ -68,27 +71,31 @@ container.id = 'vim-search-container'
// TODO(smolck): Shouldn't be necessary, right?
// document.getElementById('plugins')!.appendChild(container)

const assignStateAndRender = (newState: any) => (
Object.assign(state, newState), render(<VimSearch {...state} />, container)
const assignStateAndRender = (loadingSize: number, newState: any) => (
Object.assign(state, newState), render(<VimSearch {...state} loadingSize={loadingSize}/>, container)
)

export const hideSearch = () => {
export const hideSearch = (loadingSize: number) => {
if (winOverlay) winOverlay.remove()
assignStateAndRender({ value: '', visible: false })
assignStateAndRender(loadingSize, { value: '', visible: false })
}

export const updateSearch = (activeWindow: Window, { cmd, kind, position }: CommandUpdate) => {
export const updateSearch = (
activeWindow: Window,
loadingSize: number,
{ cmd, kind, position }: CommandUpdate
) => {
const cmdKind = kind || state.kind

!state.visible &&
setTimeout(() => {
winOverlay = activeWindow.addOverlayElement(container)
}, 1)

assignStateAndRender({
assignStateAndRender(loadingSize, {
position,
kind: cmdKind,
visible: true,
value: is.string(cmd) && state.value !== cmd ? cmd : state.value,
})
}
}
2 changes: 1 addition & 1 deletion src/components/text-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ interface Props {
ctrlC: () => void
yank: () => void
loading: boolean
loadingSize: number
loadingColor: string
pathMode: boolean
}

interface TextInputProps extends Partial<Props> {
loadingSize: number
id: string
value: string
icon: string
Expand Down
9 changes: 5 additions & 4 deletions src/ext-ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ export default (workspace: Workspace, windowManager: WindowManager) => {
windowManager.cursor.enable()
windowManager.cursor.show()

cmdlineHide()
cmdlineHide(workspace.fontDesc.size)
})
sub('cmd.update', (update: CommandUpdate) => {
windowManager.cursor.hide()
windowManager.cursor.disable()

cmdlineUpdate(update)
cmdlineUpdate(workspace.fontDesc.size, update)
})

// Popup menu
Expand Down Expand Up @@ -81,7 +81,7 @@ export default (workspace: Workspace, windowManager: WindowManager) => {
const hideSearchNess = () => {
windowManager.cursor.enable()
windowManager.cursor.show()
hideSearch()
hideSearch(workspace.fontDesc.size)

document.getElementById('keycomp-textarea')?.focus()
}
Expand All @@ -91,7 +91,7 @@ export default (workspace: Workspace, windowManager: WindowManager) => {
windowManager.cursor.hide()
windowManager.cursor.disable()

updateSearch(windowManager.getActiveWindow(), cmdUpdate)
updateSearch(windowManager.getActiveWindow(), workspace.fontDesc.size, cmdUpdate)
})

// TODO(smolck): Move `sub`s etc. here . . . maybe
Expand Down Expand Up @@ -138,6 +138,7 @@ export default (workspace: Workspace, windowManager: WindowManager) => {
vimBlur(windowManager.cursor)
render(
<LspReferences
fontSize={workspace.fontDesc.size + 2}
cursor={windowManager.cursor}
visible={true}
references={stuffToShow}
Expand Down
Loading

0 comments on commit d3de5a8

Please sign in to comment.