Skip to content

Render has off-by-one error when using previous buffer with diffLines #11

Description

@andyburris

Can't exactly pin down the fix, but here's a test program that demonstrates it:

import { useState } from 'react'
import ReactCurse, { Text, useInput } from 'react-curse'

const App = () => {
  const [counter, setCounter] = useState(0)

  useInput(
    input => {
      if (input === 'q') ReactCurse.exit()
      else setCounter(counter + 1)
    },
    [counter]
  )
  return <Text>
    <Text block>{counter % 3 === 0 ? "x   " : ""}test 1</Text>
    <Text block>{counter % 3 === 1 ? "x   " : ""}test 2</Text>
    <Text block>{counter % 3 === 2 ? "x   " : ""}test 3</Text>
  </Text>
}

ReactCurse.render(<App />)

and I found that it can be worked around by changing

react-curse/term.ts

Lines 197 to 205 in f4dc11e

const diffLine = full
? line
: line
.map((i: Char, x: number) => {
const [prevChar, prevModifier] = prevLine && prevLine[x] ? prevLine[x] : [' ', {}]
const [char, modifier] = i
return prevChar !== char || JSON.stringify(prevModifier) !== JSON.stringify(modifier) ? i : null
})
.filter(i => i !== undefined)

to just:

    const diffLine = line

so it's something about how diffLine is being used when it's null

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions