Sam Joseph
Sam Joseph

Reputation: 4704

Is it possible to get terminal text typing effects in a vscode extension?

Is it possible to get a text typing effect in a vscode extension? I'm imagining something like a intellisense autocompletion, but once you make the selection you get the characters typed out one by one rather than just having them added all in one go ...?

I know there have been some attempts to do this with jQuery:

I was wondering if I can do it with one of these:

hmm, but they rely on having a DOM, so maybe it has to be a custom vscode thing ... which I'm asking about https://github.com/microsoft/vscode/issues/87871 but still haven't got a definitive answer

Many thanks in advance

Upvotes: 0

Views: 1098

Answers (1)

Sam Joseph
Sam Joseph

Reputation: 4704

I got it working like this

let line = 0
let typing = array.reduce((promise: Promise<any>, character: string, index: number) =>
    promise.then((_: any) => 
        editor.edit(editBuilder => { return editBuilder.insert(new vscode.Position(line, index), character) })
            .then(_ => { return wait(100) })
                .then(_ => { if(character === '\n') { line++ }})    
    )
, Promise.resolve())
typing().catch((err: any) => console.log(err))

see https://github.com/microsoft/vscode/issues/87871#issuecomment-569837719 for more

Upvotes: 1

Related Questions