Skip to content

Commit

Permalink
Fix bug with text wrapping past max width
Browse files Browse the repository at this point in the history
  • Loading branch information
msvbg committed Apr 7, 2019
1 parent 339f456 commit 72c20c0
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 98 deletions.
143 changes: 69 additions & 74 deletions esy.lock/index.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions esy.lock/opam/lwt.4.2.0/opam → esy.lock/opam/lwt.4.2.1/opam
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dev-repo: "git+https://github.com/ocsigen/lwt.git"
depends: [
"cppo" {build & >= "1.1.0"}
"dune" {build}
"mmap"
"mmap" # mmap is needed as long as Lwt supports OCaml < 4.06.0.
"ocaml" {>= "4.02.0"}
"result" # result is needed as long as Lwt supports OCaml 4.02.
"seq" # seq is needed as long as Lwt supports OCaml < 4.07.0.
Expand Down Expand Up @@ -53,6 +53,6 @@ a single thread by default. This reduces the need for locks or other
synchronization primitives. Code can be run in parallel on an opt-in basis."

url {
src: "https://github.com/ocsigen/lwt/archive/4.2.0.tar.gz"
checksum: "md5=2ce7827948adc611319f9449e4519070"
src: "https://github.com/ocsigen/lwt/archive/4.2.1.tar.gz"
checksum: "md5=9d648386ca0a9978eb9487de36b781cc"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
opam-version: "2.0"
maintainer: "[email protected]"
authors: ["Jérémie Dimino <[email protected]>"]
authors: ["Jérémie Dimino <[email protected]>" "Anton Bachin" ]
homepage: "https://github.com/mirage/mmap"
bug-reports: "https://github.com/mirage/mmap/issues"
doc: "https://mirage.github.io/mmap/"
Expand All @@ -19,6 +19,6 @@ This project provides a Mmap.map_file functions for mapping files in memory.
"""
url {
src:
"https://github.com/mirage/mmap/releases/download/v1.0.2/mmap-v1.0.2.tbz"
checksum: "md5=7880d4d74b37664f9bb0906ae1cadf6b"
"https://github.com/mirage/mmap/releases/download/v1.1.0/mmap-v1.1.0.tbz"
checksum: "md5=8c5d5fbc537296dc525867535fb878ba"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ homepage: "https://github.com/ocaml-ppx/ppx_derivers"
bug-reports: "https://github.com/ocaml-ppx/ppx_derivers/issues"
dev-repo: "git://github.com/ocaml-ppx/ppx_derivers.git"
build: [
["jbuilder" "build" "-p" name "-j" jobs]
["dune" "build" "-p" name "-j" jobs]
]
depends: [
"ocaml"
"jbuilder" {build & >= "1.0+beta7"}
"dune" {build}
]
synopsis: "Shared [@@deriving] plugin registry"
description: """
Ppx_derivers is a tiny package whose sole purpose is to allow
ppx_deriving and ppx_type_conv to inter-operate gracefully when linked
as part of the same ocaml-migrate-parsetree driver."""
url {
src: "https://github.com/ocaml-ppx/ppx_derivers/archive/1.0.tar.gz"
checksum: "md5=4ddce8f43fdb9b0ef0ab6a7cbfebc3e3"
src: "https://github.com/ocaml-ppx/ppx_derivers/archive/1.2.1.tar.gz"
checksum: "md5=5dc2bf130c1db3c731fe0fffc5648b41"
}
2 changes: 1 addition & 1 deletion esy.lock/opam/ppx_tools_versioned.5.2.1/opam
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ build: [
depends: [
"ocaml" {>= "4.02.0"}
"jbuilder" {build & >= "1.0+beta17"}
"ocaml-migrate-parsetree" {>= "1.0.10"}
"ocaml-migrate-parsetree" {>= "1.0.10" & < "1.3.0"}
]
synopsis: "A variant of ppx_tools based on ocaml-migrate-parsetree"
url {
Expand Down
21 changes: 13 additions & 8 deletions esy.lock/opam/re.1.8.0/opam → esy.lock/opam/re.1.9.0/opam
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
opam-version: "2.0"

maintainer: "[email protected]"
authors: [
"Jerome Vouillon"
Expand All @@ -11,27 +12,31 @@ license: "LGPL-2.0 with OCaml linking exception"
homepage: "https://github.com/ocaml/ocaml-re"
bug-reports: "https://github.com/ocaml/ocaml-re/issues"
dev-repo: "git+https://github.com/ocaml/ocaml-re.git"

build: [
["jbuilder" "subst" "-n" name] {pinned}
["jbuilder" "build" "-p" name "-j" jobs]
["jbuilder" "runtest" "-p" name "-j" jobs] {with-test}
["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs]
["dune" "runtest" "-p" name "-j" jobs] {with-test}
]

depends: [
"ocaml" {>= "4.02.3"}
"jbuilder" {build & >= "1.0+beta10"}
"ocaml" {>= "4.02"}
"dune" {build}
"ounit" {with-test}
"seq"
]

synopsis: "RE is a regular expression library for OCaml"
description: """
Pure OCaml regular expressions with:
* Perl-style regular expressions (module Re.Perl)
* Posix extended regular expressions (module Re.Posix)
* Emacs-style regular expressions (module Re.Emacs)
* Shell-style file globbing (module Re.Glob)
* Compatibility layer for OCaml's built-in Str module (module Re.Str)"""
* Compatibility layer for OCaml's built-in Str module (module Re.Str)
"""
url {
src:
"https://github.com/ocaml/ocaml-re/releases/download/1.8.0/re-1.8.0.tbz"
checksum: "md5=765f6f8d3e6ab200866e719ed7e5178d"
"https://github.com/ocaml/ocaml-re/releases/download/1.9.0/re-1.9.0.tbz"
checksum: "md5=bddaed4f386a22cace7850c9c7dac296"
}
14 changes: 9 additions & 5 deletions src/Core/TextWrapping.re
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,17 @@ let wrapText = (~text, ~measureWidth, ~maxWidth, ~wrapHere) => {

if (width >= maxWidth) {
let (line, lineWidth) = subAndMeasure(acc.beginIndex, acc.endIndex);
let (lastLine, lastLineWidth) =
subAndMeasure(acc.endIndex + 2, index);
if (acc.endIndex + 2 > index) {
{...acc, lines: [line, ...acc.lines], currMaxWidth: lineWidth};
} else {
let (lastLine, lastLineWidth) =
subAndMeasure(acc.endIndex + 2, index);

let currMaxWidth =
max(lastLineWidth, max(acc.currMaxWidth, lineWidth));
let currMaxWidth =
max(lastLineWidth, max(acc.currMaxWidth, lineWidth));

{...acc, lines: [lastLine, line, ...acc.lines], currMaxWidth};
{...acc, lines: [lastLine, line, ...acc.lines], currMaxWidth};
};
} else {
let (line, lineWidth) = subAndMeasure(acc.beginIndex, index);

Expand Down
16 changes: 16 additions & 0 deletions test/Core/TextWrappingTests.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
open Rejest;

open Revery_Core;

test("TextWrapping", () =>
test("doesn't crash when supplied with text that is too wide", () => {
let measureWidth = _ => 14;
let wrapHere = TextWrapping.isWhitespaceWrapPoint;
let text = "W";
let maxWidth = 12;
let (text, width) =
TextWrapping.wrapText(~text, ~measureWidth, ~maxWidth, ~wrapHere);
expect(text).toEqual(["W"]);
expect(width).toEqual(14);
})
);

0 comments on commit 72c20c0

Please sign in to comment.