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

JS highlights many places during multi-word term creation. #69

Closed
jzohrab opened this issue Nov 8, 2022 · 5 comments
Closed

JS highlights many places during multi-word term creation. #69

jzohrab opened this issue Nov 8, 2022 · 5 comments
Labels
bug Something isn't working ui Any problem related to the User Interface

Comments

@jzohrab
Copy link

jzohrab commented Nov 8, 2022

Prior to adding the new phrase "Con el tiempo":

image

After! :-)

image

On page reload, the highlight is where it should be:

image

Mac/chrome ... I'm investigating a fix now.

@jzohrab
Copy link
Author

jzohrab commented Nov 8, 2022

edit_mword.php gens bad javascript at some point:

    <title>LWT :: New Term: con el tiempo</title>
</head>
...
        title = make_tooltip(
            {"22":"Con el tiempo","1":"Con el tiempo","625":"con el tiempo","159":"Con el tiempo","589":"con el tiempo","1832":"con el tiempo","88":"con el tiempo","481":"con el tiempo","541":"con el tiempo","1174":"con el tiempo","988":"Con el tiempo","221":"con el tiempo","939":"Con el tiempo","55":"Con el tiempo","186":"Con el tiempo","886":"con el tiempo","705":"con el tiempo","281":"Con el tiempo","639":"Con el tiempo","897":"Con el tiempo","974":"con el tiempo","81":"Con el tiempo","1063":"con el tiempo","1342":"con el tiempo","597":"con el tiempo","513":"con el tiempo","739":"Con el tiempo"}, term.data_trans, term.data_rom, 
            parseInt(term.data_status, 10)
        );
    term['title'] = title;
    let attrs = ""; 
    Object.entries(term).forEach(([k, v]) => attrs += " " + k + '="' + v + '"');
    // keys(term).map((k) => k + '="' + term[k] + '"').join(" ");
    
    newExpressionInteractable(
        {"22":"Con el tiempo","1":"Con el tiempo","625":"con el tiempo","159":"Con el tiempo","589":"con el tiempo","1832":"con el tiempo","88":"con el tiempo","481":"con el tiempo","541":"con el tiempo","1174":"con el tiempo","988":"Con el tiempo","221":"con el tiempo","939":"Con el tiempo","55":"Con el tiempo","186":"Con el tiempo","886":"con el tiempo","705":"con el tiempo","281":"Con el tiempo","639":"Con el tiempo","897":"Con el tiempo","974":"con el tiempo","81":"Con el tiempo","1063":"con el tiempo","1342":"con el tiempo","597":"con el tiempo","513":"con el tiempo","739":"Con el tiempo"}, 
        attrs,
        3, 
        "con\u00a420el\u00a420tiempo",
        true    );

@jzohrab
Copy link
Author

jzohrab commented Nov 8, 2022

(I can't follow what the intent is with the some parts of the code, especially insert_standard_expression ... need some help from @HugoFara :-) )

I added a small logging function to a test branch in my fork, branch name investigate_69_multiword_term_highlighting, https://github.com/jzohrab/lwt/tree/investigate_69_multiword_term_highlighting, just the last two commits.

edit_word.php eventually makes a call to {"file":"ROOT/inc\/session_utility.php","line":4050,"function":"insert_standard_expression" via the call stack:

Call stack
{"file":"ROOT/edit_mword.php","line":633,"function":"edit_mword_page","args":[]}

{"file":"ROOT/edit_mword.php","line":595,"function":"edit_mword_do_operation","args":[{"id":"5030","lgid":1,"text":"Con el tiempo","textlc":"con el tiempo","status":1,"translation":"test","sentence":"{Con el tiempo} pas\u00f3 a adoptar novelistas malditos[SNIP]","roman":"","wordcount":3,"statuschanged":null}]},

{"file":"ROOT/edit_mword.php","line":143,"function":"edit_mword_do_insert","args":[{"id":"5030","lgid":1,"text":"Con el tiempo","textlc":"con el tiempo","status":1,"translation":"test","sentence":"{Con el tiempo} pas\u00f3 a adoptar novelistas malditos, a lo mejor porque su padre quiso ser uno y nunca lo consigui\u00f3.","roman":"","wordcount":3,"statuschanged":null}]},

{"file":"ROOT/edit_mword.php","line":208,"function":"insertExpressions","args":["con el tiempo",1,"5030",3,0]},

calls inc/session_utility.php, function insertExpressions()

calls inc/session_utility.php, function insert_standard_expression()

In insert_standard_expression, a query is run that gets every sentence containing that phrase:

running query to get sentences??
SELECT * FROM sentences 
        WHERE SeLgID = 1 AND SeText LIKE '%con el tiempo%'

(In this case, here's the data:)

db dump
mysql> select LEFT(SeText, 20), SeFirstPos from sentences WHERE SeLgID = 1 AND SeText LIKE '%con el tiempo%';
+------------------------+------------+
| LEFT(SeText, 20)       | SeFirstPos |
+------------------------+------------+
|  Con el tiempo, mi m   |         22 |
| Con el tiempo desech   |          1 |
...
|  Porque alguien más    |        495 |
|  Con el tiempo pasó    |        739 |
+------------------------+------------+

... and then in insert_standard_expression, the code builds a dict of ((SeFirstPos + some_stuff) -> phrase) for each sentence (??) in a big while loop. See partial trace:

Trace

started while ---------------
string = 
  Con el tiempo, mi madre decidió que quería regresar a España. 
appendtext is now:
{"22":"Con el tiempo"}

started while ---------------
string = 
 Con el tiempo deseché la idea de la carta y supuse que, ya puestos, sería más práctico empezar con la obra maestra. 
appendtext is now:
{"22":"Con el tiempo","1":"Con el tiempo"}

started while ---------------
... [ETC, snipping all of these, until we hit the sentence I actually used] ...

started while ---------------
string = 
  Con el tiempo pasó a adoptar novelistas malditos, a lo mejor porque su padre quiso ser uno y nunca lo consiguió. 
appendtext is now:
{"22":"Con el tiempo","1":"Con el tiempo","625":"con el tiempo","159":"Con el tiempo","589":"con el tiempo",..."739":"Con el tiempo"}
...

This dict is then passed to new_expression_interactable2() as $appendtext:
{"22":"Con el tiempo","1":"Con el tiempo","625":"con el tiempo","159":"Con el tiempo","589":"con el tiempo",..."739":"Con el tiempo"}

... and then this eventually makes it to src/js/user_interactions.js newExpressionInteractable, which adds everything to the page.

@HugoFara HugoFara added bug Something isn't working ui Any problem related to the User Interface labels Nov 9, 2022
ProgramComputer added a commit to ProgramComputer/lwt that referenced this issue Dec 29, 2023
@ProgramComputer
Copy link

ProgramComputer commented Dec 29, 2023

@HugoFara I can't reproduce this bug, but found another bug #170. I'm on d246f05.

– Casi todos. Por fortuna, la secretaria de Cabestany, al oír lo de la oferta, tuvo una corazonada y, por su cuenta y riesgo,
 fue al almacén y se llevó un ejemplar de cada título de Carax a su casa. Ella era la que mantenía toda la correspondencia 
con Carax y, a lo largo de los años, habían entablado cierta amistad. Se llamaba Nuria, y me parece que ella era la única 
persona en la editorial, y probablemente en toda Barcelona, que se leía las novelas de Carax. Nuria siente debilidad por 
las causas perdidas. De pequeña recogía animalillos de la calle y los llevaba a casa. Con el tiempo pasó a adoptar 
novelistas malditos, a lo mejor porque su padre quiso ser uno y nunca lo consiguió.

@HugoFara
Copy link
Owner

HugoFara commented Jan 1, 2024

I haven't been able to reproduce the bug either, and no comments came here so it may have been fixed at some point, I'm closing it for now.

@HugoFara HugoFara closed this as not planned Won't fix, can't repro, duplicate, stale Jan 1, 2024
@HugoFara HugoFara reopened this Jan 1, 2024
@HugoFara
Copy link
Owner

HugoFara commented Jan 1, 2024

db dump

... and then in insert_standard_expression, the code builds a dict of ((SeFirstPos + some_stuff) -> phrase) for each sentence (??) in a big while loop. See partial trace:
Trace

This dict is then passed to new_expression_interactable2() as $appendtext: {"22":"Con el tiempo","1":"Con el tiempo","625":"con el tiempo","159":"Con el tiempo","589":"con el tiempo",..."739":"Con el tiempo"}

Okayyyy figured it out while documenting the functions!

Bug steps/call stack

Basically they steps are:

  1. User creates new expression edit_mword.php. From single text.
  2. The expression is sent to the database to be saved insert_standard_expression. The database returns all appearances of the expression in all texts, with position in each text (???), without saying which position is which text.
  3. new_expression_interactable2 displays the multi-word at all the indicated position (is if the positions were from current text).
  4. If the expression is in several texts, a mess appears on screen.

To reproduce

Have the same expression in several texts.

For the future

I should simplify the call stack to:

Create expression (JS)
→ display it (step 3).
→ save to database (step 2).

That should remove the back and forth.

For now

At step 2, I added a text key in the array. Step 3 uses it to update only the current text. I won't it won't cause issues until I implement the clean version.

That was a nice and nasty bug, cheers!

HugoFara added a commit that referenced this issue Jan 3, 2024
New databse migration strategy.
Fixes feeds (#168).
Adds missing documentation to Docker (#146, #160).
Changes in PHP and JS globals.
Fixes reading position was not set.
Read text through API (#153, #155).
Fixes word was not saved/deleted.
Fixes #170 and #69.
Updates API (#175).
Adds dependency to php-xml (#178, #181).
Updates makefile (#179).
Adds MeCab support on Mac (#135).
Adds the option to hide/show word romanization (#119).
Raises URL size limit to 2048 (#144).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ui Any problem related to the User Interface
Projects
None yet
Development

No branches or pull requests

3 participants