diff --git a/interfacer/test/tty/setup.go b/interfacer/test/tty/setup.go index 196d988..d24dd9b 100644 --- a/interfacer/test/tty/setup.go +++ b/interfacer/test/tty/setup.go @@ -95,7 +95,7 @@ func sleepUntilPageLoad(maxTime time.Duration) { for time.Since(start) < maxTime { if browsh.CurrentTab != nil { if browsh.CurrentTab.PageState == "parsing_complete" { - time.Sleep(100 * time.Millisecond) + time.Sleep(200 * time.Millisecond) return } } diff --git a/interfacer/test/tty/tty_test.go b/interfacer/test/tty/tty_test.go index 780b56d..b9156c7 100644 --- a/interfacer/test/tty/tty_test.go +++ b/interfacer/test/tty/tty_test.go @@ -34,8 +34,8 @@ var _ = Describe("Showing a basic webpage", func() { }) It("should navigate to a new page by clicking a link", func() { - Expect("Another▄page").To(BeInFrameAt(12, 19)) - mouseClick(12, 19) + Expect("Another▄page").To(BeInFrameAt(12, 18)) + mouseClick(12, 18) Expect("Another").To(BeInFrameAt(0, 0)) }) @@ -46,7 +46,7 @@ var _ = Describe("Showing a basic webpage", func() { It("should scroll the page by one page", func() { SpecialKey(tcell.KeyPgDn) - Expect("continuing▄with▄a▄variety▄of▄fish").To(BeInFrameAt(12, 12)) + Expect("continuing▄with▄a▄variety▄of▄fish").To(BeInFrameAt(12, 13)) }) Describe("Text Input", func() { @@ -54,7 +54,7 @@ var _ = Describe("Showing a basic webpage", func() { BeforeEach(func() { SpecialKey(tcell.KeyDown) SpecialKey(tcell.KeyDown) - simScreen.InjectMouse(12, 17, tcell.Button1, tcell.ModNone) + simScreen.InjectMouse(12, 16, tcell.Button1, tcell.ModNone) }) It("should have basic cursor movement", func() { @@ -64,12 +64,12 @@ var _ = Describe("Showing a basic webpage", func() { SpecialKey(tcell.KeyLeft) SpecialKey(tcell.KeyLeft) Keyboard("1") - Expect("|1|2|").To(BeInFrameAt(12, 17)) + Expect("|1|2|").To(BeInFrameAt(12, 16)) }) It("should scroll single line boxes on overflow", func() { Keyboard("12345678901234567890") - Expect("45678901234567890").To(BeInFrameAt(12, 17)) + Expect("45678901234567890").To(BeInFrameAt(12, 16)) }) It("should scroll overflowed boxes to the left and right", func() { @@ -77,18 +77,18 @@ var _ = Describe("Showing a basic webpage", func() { for i := 0; i < 19; i++ { SpecialKey(tcell.KeyLeft) } - Expect("23456789012345678").To(BeInFrameAt(12, 17)) + Expect("23456789012345678").To(BeInFrameAt(12, 16)) for i := 0; i < 19; i++ { SpecialKey(tcell.KeyRight) } - Expect("45678901234567890").To(BeInFrameAt(12, 17)) + Expect("45678901234567890").To(BeInFrameAt(12, 16)) }) It("should submit text into an input box", func() { - Expect("Unsubmitted").To(BeInFrameAt(12, 21)) + Expect("Unsubmitted").To(BeInFrameAt(12, 20)) Keyboard("Reverse Me!") SpecialKey(tcell.KeyEnter) - Expect("!eM▄esreveR").To(BeInFrameAt(12, 21)) + Expect("!eM▄esreveR").To(BeInFrameAt(12, 20)) }) }) @@ -110,7 +110,7 @@ var _ = Describe("Showing a basic webpage", func() { Keyboard(`So here is a lot of text that will hopefully split across lines`) SpecialKey(tcell.KeyEnter) Keyboard(`And here is even more filler, it's endless!`) - Expect("filler, it's endless!").To(BeInFrameAt(1, 7)) + Expect("filler, it's endless!").To(BeInFrameAt(1, 6)) for i := 1; i <= 6; i++ { SpecialKey(tcell.KeyUp) } @@ -153,7 +153,7 @@ var _ = Describe("Showing a basic webpage", func() { Describe("Rendering", func() { It("should reset page scroll to zero on page load", func() { SpecialKey(tcell.KeyPgDn) - Expect("continuing▄with▄a▄variety▄of▄fish").To(BeInFrameAt(12, 12)) + Expect("continuing▄with▄a▄variety▄of▄fish").To(BeInFrameAt(12, 13)) GotoURL(testSiteURL + "/smorgasbord/another.html") Expect("Another▄webpage").To(BeInFrameAt(1, 3)) }) diff --git a/webext/src/background/dimensions.js b/webext/src/background/dimensions.js index 3f6bef9..c758eac 100644 --- a/webext/src/background/dimensions.js +++ b/webext/src/background/dimensions.js @@ -43,10 +43,8 @@ export default class extends utils.mixins(CommonMixin) { const window_width = parseInt(Math.round(this.tty.width * this.char.width)); // Leave room for tabs and URL bar const tty_dom_height = this.tty.height - 2; - // I don't know why we have to add 4 more lines to the window height?? But without - // it text doesn't fill the bottom of the TTY. const window_height = parseInt(Math.round( - (tty_dom_height + 4) * this.char.height + tty_dom_height * this.char.height )); const current_window = browser.windows.getCurrent(); current_window.then( diff --git a/webext/src/dom/dimensions.js b/webext/src/dom/dimensions.js index aa18d72..36d05fb 100644 --- a/webext/src/dom/dimensions.js +++ b/webext/src/dom/dimensions.js @@ -14,8 +14,8 @@ export default class extends utils.mixins(CommonMixin) { if (TEST) { this._char_height_magic_number = 0; } else { - // TODO: WTF is this magic number? - this._char_height_magic_number = 4; + // TODO: WTF is this magic number? The gap between lines? + this._char_height_magic_number = 5; } // This is the region outside the visible area of the TTY that is pre-parsed and diff --git a/webext/src/dom/text_builder.js b/webext/src/dom/text_builder.js index f6d04c7..c33a10e 100644 --- a/webext/src/dom/text_builder.js +++ b/webext/src/dom/text_builder.js @@ -49,6 +49,7 @@ export default class extends utils.mixins(CommonMixin) { _updateState() { this.tty_grid.cells = []; this._parse_started_elements = []; + this._previous_dom_box = {}; this._convertSubFrameToViewportCoords(); } @@ -231,7 +232,6 @@ export default class extends utils.mixins(CommonMixin) { // real browser. _positionSingleTextNode() { this._dom_box = {}; - this._previous_dom_box = {}; for (const dom_box of this._getNodeDOMBoxes()) { if (!this._isDOMRectInSubFrame(dom_box)) { continue } this._dom_box.top = dom_box.top; @@ -271,8 +271,8 @@ export default class extends utils.mixins(CommonMixin) { this._dom_box = this._convertDOMRectToAbsoluteCoords(this._dom_box); this._createSyncedTTYBox(); this._createTrackers() - this._ignoreUnrenderedWhitespace(); this._setCurrentCharacter(); + this._ignoreUnrenderedWhitespace(); } // Note that it's possible for this._text to straddle many DOM boxes @@ -286,8 +286,8 @@ export default class extends utils.mixins(CommonMixin) { // each step is a new single cell within the TTY. _createTrackers() { this._dom_tracker = { - x: utils.snap(this._dom_box.left), - y: utils.snap(this._dom_box.top) + x: this._dom_box.left, + y: this._dom_box.top } this._tty_tracker = { x: this._tty_box.col_start, @@ -327,7 +327,7 @@ export default class extends utils.mixins(CommonMixin) { // Is the current DOM rectangle further down the page than the previous? _isNewLine() { - if (this._previous_dom_box === {}) return false; + if (Object.keys(this._previous_dom_box).length === 0) return false; return this._dom_box.top > this._previous_dom_box.top }