Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with text wrapping past max width #434

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions bench.esy.lock/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@
],
"devDependencies": [ "[email protected]@d41d8cd9" ]
},
"@opam/tyxml@opam:4.3.0@b35a7c40": {
"id": "@opam/tyxml@opam:4.3.0@b35a7c40",
"@opam/tyxml@opam:4.3.0@15e44054": {
"id": "@opam/tyxml@opam:4.3.0@15e44054",
"name": "@opam/tyxml",
"version": "opam:4.3.0",
"source": {
Expand Down Expand Up @@ -579,7 +579,7 @@
},
"overrides": [],
"dependencies": [
"[email protected]@d41d8cd9", "@opam/tyxml@opam:4.3.0@b35a7c40",
"[email protected]@d41d8cd9", "@opam/tyxml@opam:4.3.0@15e44054",
"@opam/dune@opam:1.7.3@72aad784",
"@opam/base-bytes@opam:base@19d0c2ff",
"@esy-ocaml/[email protected]@d41d8cd9"
Expand Down Expand Up @@ -657,7 +657,7 @@
},
"overrides": [],
"dependencies": [
"[email protected]@d41d8cd9", "@opam/tyxml@opam:4.3.0@b35a7c40",
"[email protected]@d41d8cd9", "@opam/tyxml@opam:4.3.0@15e44054",
"@opam/result@opam:1.3@bee8bf2e", "@opam/fpath@opam:0.7.2@45477b93",
"@opam/dune@opam:1.7.3@72aad784", "@opam/cppo@opam:1.6.5@bec3dbd9",
"@opam/cmdliner@opam:1.0.2@8ab0598a",
Expand Down Expand Up @@ -772,8 +772,8 @@
],
"devDependencies": [ "[email protected]@d41d8cd9" ]
},
"@opam/merlin-extend@opam:0.3@e1fc0d08": {
"id": "@opam/merlin-extend@opam:0.3@e1fc0d08",
"@opam/merlin-extend@opam:0.3@0af73a50": {
"id": "@opam/merlin-extend@opam:0.3@0af73a50",
"name": "@opam/merlin-extend",
"version": "opam:0.3",
"source": {
Expand Down Expand Up @@ -1568,7 +1568,7 @@
"[email protected]@d41d8cd9", "@opam/result@opam:1.3@bee8bf2e",
"@opam/ocamlfind@opam:1.8.0@f744a0c5",
"@opam/ocaml-migrate-parsetree@opam:1.2.0@23e55f71",
"@opam/merlin-extend@opam:0.3@e1fc0d08",
"@opam/merlin-extend@opam:0.3@0af73a50",
"@opam/menhir@opam:20181113@0c8257a8",
"@opam/dune@opam:1.7.3@72aad784"
],
Expand Down
2 changes: 1 addition & 1 deletion bench.esy.lock/opam/merlin-extend.0.3/opam
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build: [make]
install: [make "install"]
remove: ["ocamlfind" "remove" "merlin_extend"]
depends: [
"ocaml" {>= "4.02.3"}
"ocaml" {>= "4.02.3" & < "4.08.0"}
"ocamlfind" {build}
"cppo" {build}
]
Expand Down
3 changes: 2 additions & 1 deletion bench.esy.lock/opam/tyxml.4.3.0/opam
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ build: [

depends: [
"ocaml" {>= "4.02"}
"re" {>= "1.5.0"}
("ocaml" {>= "4.07"} | "re" {>= "1.8.0"})
"dune" {build}
"alcotest" {with-test}
"seq"
"uutf" {>= "1.0.0"}
"re" {>= "1.5.0"}
]

synopsis:"TyXML is a library for building correct HTML and SVG documents"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--- ./extend_helper.ml
+++ ./extend_helper.ml
@@ -1,13 +1,6 @@
-(*pp cppo -V OCAML:`ocamlc -version` *)
open Parsetree
open Extend_protocol

-#if OCAML_VERSION < (4, 3, 0)
-# define CONST_STRING Asttypes.Const_string
-#else
-# define CONST_STRING Parsetree.Pconst_string
-#endif
-
(** Default implementation for [Reader_def.print_outcome] using
[Oprint] from compiler-libs *)
let print_outcome_using_oprint ppf = function
@@ -28,7 +21,7 @@
pstr_loc = Location.none;
pstr_desc = Pstr_eval ({
pexp_loc = Location.none;
- pexp_desc = Pexp_constant (CONST_STRING (msg, None));
+ pexp_desc = Pexp_constant (Asttypes.Const_string (msg, None));
pexp_attributes = [];
}, []);
}]
@@ -112,7 +105,7 @@
let msg = match payload with
| PStr [{
pstr_desc = Pstr_eval ({
- pexp_desc = Pexp_constant (CONST_STRING (msg, _));
+ pexp_desc = Pexp_constant (Asttypes.Const_string (msg, _));
}, _);
}] -> msg
| _ -> "Warning: extension produced an incorrect syntax-error node"
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"buildEnv": {
"PATCH_CMD": "#{ocaml.version == '4.2.3007' ? 'patch -p1 < merlin-extend-winfix-4.2.3007.patch' : 'patch -p1 < merlin-extend-winfix.patch'}"
},
"build": [
[
"bash",
"-c",
"#{os == 'windows' ? 'patch -p1 < merlin-extend-winfix.patch' : 'true'}"
"#{os == 'windows' ? $PATCH_CMD : 'true'}"
],
[
"make"
Expand Down
14 changes: 7 additions & 7 deletions esy.lock/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@
],
"devDependencies": [ "[email protected]@d41d8cd9" ]
},
"@opam/tyxml@opam:4.3.0@b35a7c40": {
"id": "@opam/tyxml@opam:4.3.0@b35a7c40",
"@opam/tyxml@opam:4.3.0@15e44054": {
"id": "@opam/tyxml@opam:4.3.0@15e44054",
"name": "@opam/tyxml",
"version": "opam:4.3.0",
"source": {
Expand Down Expand Up @@ -579,7 +579,7 @@
},
"overrides": [],
"dependencies": [
"[email protected]@d41d8cd9", "@opam/tyxml@opam:4.3.0@b35a7c40",
"[email protected]@d41d8cd9", "@opam/tyxml@opam:4.3.0@15e44054",
"@opam/dune@opam:1.7.3@72aad784",
"@opam/base-bytes@opam:base@19d0c2ff",
"@esy-ocaml/[email protected]@d41d8cd9"
Expand Down Expand Up @@ -657,7 +657,7 @@
},
"overrides": [],
"dependencies": [
"[email protected]@d41d8cd9", "@opam/tyxml@opam:4.3.0@b35a7c40",
"[email protected]@d41d8cd9", "@opam/tyxml@opam:4.3.0@15e44054",
"@opam/result@opam:1.3@bee8bf2e", "@opam/fpath@opam:0.7.2@45477b93",
"@opam/dune@opam:1.7.3@72aad784", "@opam/cppo@opam:1.6.5@bec3dbd9",
"@opam/cmdliner@opam:1.0.2@8ab0598a",
Expand Down Expand Up @@ -772,8 +772,8 @@
],
"devDependencies": [ "[email protected]@d41d8cd9" ]
},
"@opam/merlin-extend@opam:0.3@e1fc0d08": {
"id": "@opam/merlin-extend@opam:0.3@e1fc0d08",
"@opam/merlin-extend@opam:0.3@0af73a50": {
"id": "@opam/merlin-extend@opam:0.3@0af73a50",
"name": "@opam/merlin-extend",
"version": "opam:0.3",
"source": {
Expand Down Expand Up @@ -1568,7 +1568,7 @@
"[email protected]@d41d8cd9", "@opam/result@opam:1.3@bee8bf2e",
"@opam/ocamlfind@opam:1.8.0@f744a0c5",
"@opam/ocaml-migrate-parsetree@opam:1.2.0@23e55f71",
"@opam/merlin-extend@opam:0.3@e1fc0d08",
"@opam/merlin-extend@opam:0.3@0af73a50",
"@opam/menhir@opam:20181113@0c8257a8",
"@opam/dune@opam:1.7.3@72aad784"
],
Expand Down
2 changes: 1 addition & 1 deletion esy.lock/opam/merlin-extend.0.3/opam
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build: [make]
install: [make "install"]
remove: ["ocamlfind" "remove" "merlin_extend"]
depends: [
"ocaml" {>= "4.02.3"}
"ocaml" {>= "4.02.3" & < "4.08.0"}
"ocamlfind" {build}
"cppo" {build}
]
Expand Down
3 changes: 2 additions & 1 deletion esy.lock/opam/tyxml.4.3.0/opam
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ build: [

depends: [
"ocaml" {>= "4.02"}
"re" {>= "1.5.0"}
("ocaml" {>= "4.07"} | "re" {>= "1.8.0"})
"dune" {build}
"alcotest" {with-test}
"seq"
"uutf" {>= "1.0.0"}
"re" {>= "1.5.0"}
]

synopsis:"TyXML is a library for building correct HTML and SVG documents"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--- ./extend_helper.ml
+++ ./extend_helper.ml
@@ -1,13 +1,6 @@
-(*pp cppo -V OCAML:`ocamlc -version` *)
open Parsetree
open Extend_protocol

-#if OCAML_VERSION < (4, 3, 0)
-# define CONST_STRING Asttypes.Const_string
-#else
-# define CONST_STRING Parsetree.Pconst_string
-#endif
-
(** Default implementation for [Reader_def.print_outcome] using
[Oprint] from compiler-libs *)
let print_outcome_using_oprint ppf = function
@@ -28,7 +21,7 @@
pstr_loc = Location.none;
pstr_desc = Pstr_eval ({
pexp_loc = Location.none;
- pexp_desc = Pexp_constant (CONST_STRING (msg, None));
+ pexp_desc = Pexp_constant (Asttypes.Const_string (msg, None));
pexp_attributes = [];
}, []);
}]
@@ -112,7 +105,7 @@
let msg = match payload with
| PStr [{
pstr_desc = Pstr_eval ({
- pexp_desc = Pexp_constant (CONST_STRING (msg, _));
+ pexp_desc = Pexp_constant (Asttypes.Const_string (msg, _));
}, _);
}] -> msg
| _ -> "Warning: extension produced an incorrect syntax-error node"
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"buildEnv": {
"PATCH_CMD": "#{ocaml.version == '4.2.3007' ? 'patch -p1 < merlin-extend-winfix-4.2.3007.patch' : 'patch -p1 < merlin-extend-winfix.patch'}"
},
"build": [
[
"bash",
"-c",
"#{os == 'windows' ? 'patch -p1 < merlin-extend-winfix.patch' : 'true'}"
"#{os == 'windows' ? $PATCH_CMD : 'true'}"
],
[
"make"
Expand Down
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);
})
);