DominicBoettger / hyphenator

Automatically exported from code.google.com/p/hyphenator
0 stars 0 forks source link

Copy & Paste and Search broken on Safari #34

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Hypenate a text for example "example"
2. Search for "example"
3. Copy it, Paste it in TextEdit or some other Text editor

What is the expected output? What do you see instead?
Expected:
 2: example found
 3: Text "example"
Actual Result:
 2: example not found
 3: Text "ex amp le"

What version of the product are you using? On what operating system?
.10b OSX 10.5 Safari 3.2

Please provide any additional information below.
Firefox on OSX doesn't have this problem. I don't know if it is an issure of 
the hyphenator script 
or an issure of Safari

Original issue reported on code.google.com by nils.win...@gmail.com on 28 Nov 2008 at 2:26

GoogleCodeExporter commented 9 years ago
Thank you for your feedback.

It's a known problem 
(http://code.google.com/p/hyphenator/wiki/8CompatibilityMatrix) – but it's 
IMHO a 
problem to be solved by the browser or the text editor.
I'm not sure if this is a bug. The HTML-Spec says: "For operations such as 
searching and sorting, the soft 
hyphen should always be ignored." 
(http://www.w3.org/TR/html401/struct/text.html#h-9.3.3) It says 
nothing about copying and pasting.
Text editors displaying the soft hyphen, even if the line isn't broken aren't 
following the Unicode-Spec either.

I thought about disabling hyphenation, when text is selected. But disabling 
hyphenation causes redrawing of 
the page -> selection breaks, you get lost.

Another solution may be to remove unused soft hyphens by Hyphenator and thus to 
reduce the impact on 
copied text.
This is infact really interesting (just stormed my brain;-)

More on this later...

Original comment by mathiasn...@gmail.com on 28 Nov 2008 at 3:53

GoogleCodeExporter commented 9 years ago
Removing unused shys is quite complicated.
The solution I had in mind is to compare the offsetHeight of a word with the 
line-height. If the offsetHeight is 
the douple of the lineheight, the word has been splitted across lines...
Thus to check offsetHeight, I'd had to put each word in a <span>.

Furthermore offsetHeight isn't an official standard.

Original comment by mathiasn...@gmail.com on 3 Dec 2008 at 2:17

GoogleCodeExporter commented 9 years ago
Oh:

http://developer.apple.com/documentation/AppleApplications/Conceptual/SafariJSPr
ogTopics/Tasks/CopyAndP
aste.html
http://www.jeffothy.com/weblog/clipboard-copy/

Original comment by mathiasn...@gmail.com on 18 Mar 2009 at 7:52

GoogleCodeExporter commented 9 years ago
Safari has a serious bug here that makes it unusable for me: 
https://bugs.webkit.org/show_bug.cgi?id=26774

Further, Firefox does not support access to the copied text, yet.

Last hope is IE, wich I didn't check until now...

Original comment by mathiasn...@gmail.com on 12 Jul 2009 at 10:03

GoogleCodeExporter commented 9 years ago
The function Hyphenator.toggleHyphenation() allows disabling hyphenation when 
the user selected text
Mit der Funktion Hyphenator.toggleHyphenation() kann die Silbentrennung 
deaktiviert werden, wenn Text 
ausgewählt wird.

If you use a framework like dojo you could do it when the user presses strg+c 
or cmd+c (dojo.keys)

Original comment by sebila...@googlemail.com on 1 Apr 2010 at 8:08

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago

*Using Dojo 1.4 Javascript Framework to fix all copy&paste issues you could do: 
*

// include only dojo in your main html/php document
FIRST:
    <script type="text/javascript">var djConfig = {isDebug:false, parseOnLoad:true};</script>
    <script type="text/javascript" src="framework/dojo/dojo.js"></script> 
SECOND:
    <script type="text/javascript" src="framework/hyphenator/Hyphenator.js"></script>
THIRD:      
    <script type="text/javascript" 
src="framework/hyphenator/MYSCRIPTWHEREFOLLOWINGGOES.js"></script>

// nothing to require, only dojo base

1.
Für manche Firefox Versionen muss wie geschrieben eine Extra Lösung her 
(siehe auch 3a):
((Also in den <body> tag)) , ((put In the <body> tag:))
{{{
<body onkeydown="keyFF(event);">
}}}

--------------------------------------------------------------------------------
----
------------------------------------------------------
2.
((Die globalen Variablen)) , ((global variables))
{{{
var HYPHENATION = true;
var TEXTSELECTION = new Array('','');
}}}

--------------------------------------------------------------------------------
----
------------------------------------------------------
3.
((3 Funktionen in Dein Javascript (MYSCRIPTWHEREFOLLOWINGGOES.js) einfügen)), 
((3 functions to add to 
YOUR JS))
{{{

function reHyphenate(){
    if( HYPHENATION == false ){
        Hyphenator.toggleHyphenation();
        HYPHENATION = true;
    }
}
function keyFF(e){
    if( dojo.isFF ){
        if(e.keyCode == 67){ reHyphenate(); }
    }
}

function analyzeSelection() {
    if (dojo.isIE && dojo.isIE > 4) {
        if (document.selection) {
        TEXTSELECTION[1] = document.selection.createRange().text;
        }
    } else { 
        TEXTSELECTION[1] = document.getSelection();
    }
    if(TEXTSELECTION[1] == TEXTSELECTION[0]  || TEXTSELECTION[1]  == ""){
    reHyphenate();
    } 
}

}}}

--------------------------------------------------------------------------------
----
------------------------------------------------------
4.
In Dein JS (MYSCRIPTWHEREFOLLOWINGGOES.js) im dojo.addOnLoad einfügen:
Add to *dojo.addOnLoad*:
{{{

////////////////////////////////////////////////////////////////////////////////
//////////

/* 
executed if mousedown
wird ausgeführt, sobald im jeweiligen silbengetrennten Bereich die Maus unten 
ist  -  
die Silbentrennung wird ausgeschaltet
*/

dojo.connect(dojo.byId("myHyphenatedNodeID"), "onmousedown", function(e){
    if( HYPHENATION == true ){
        Hyphenator.toggleHyphenation();
        HYPHENATION = false;
    }                                                
});

////////////////////////////////////////////////////////////////////////////////
//////////

/* 
executed if mouseup, checks selection
wird ausgeführt, sobald im jeweiligen silbengetrennten Bereich die Maus wieder 
oben ist
bewirkt Überprüfung, ob eine Auswahl gemacht wurde und wenn ja, welche  -  
falls nicht, wird die Silbentrennung eingeschaltet
*/

dojo.connect(dojo.byId("myHyphenatedNodeID"), "onmouseup", "analyzeSelection");

////////////////////////////////////////////////////////////////////////////////
//////////

/* 
executed immediately before copy
wird ausgeführt, sobald "COPY"(Mac:cmd/apfel | Win:Strg) und "c" gleichzeitig 
gedrückt wird, 
also: unmittelbar VOR dem Kopieren
unmittelbar NACH dem Kopieren wird die Silbentrennung eingeschaltet (timeout)
*/

dojo.connect(dojo.byId("myBodyID"), "onkeypress", function(e){
   switch(e.charOrCode){
    case dojo.keys.copyKey && 'c':
        //jetzt z.B. mittels dojo.style() die Schrift schwarz
        setTimeout(reHyphenate,80);
    break;
   }
});

////////////////////////////////////////////////////////////////////////////////
//////////

/* 
bei OS X - COPY&TAB is onblur
*/

dojo.connect(window, "onblur", "reHyphenate");
}}}
--------------------------------------------------------------------------------
----
------------------------------------------------------
FERTIG! READY!
--------------------------------------------------------------------------------
----
------------------------------------------------------
better to be done via dojo.query but more complex

Das ganze ist vermutlich auch mittels dem Key Plugin bei jQuery möglich, aber 
ich benutze halt dojo ...

Das obige halte ich für das einfachste Beispiel.
Das ganze wird natürlich eleganter (aber auch individueller/komplexer), wenn 
man es mit dojo.query macht:

Obige Schritte AUSSER 4 ausführen und statt 4:

1.
Z.B.:
Die Silbentrennung nur bei allen <p> Elementen (in diesem Fall) irgendwo 
in myHyphenatedNodeID ausführen 
:
{{{
dojo.query("#myHyphenatedNodeID p").addClass("hyphenate");
}}}
2.
Das Äquivalent im dojo.addOnLoad wäre dann:
{{{
dojo.query("#myHyphenatedNodeID p").onmousedown(function(e){
    if( HYPHENATION == true ){
        Hyphenator.toggleHyphenation();
        HYPHENATION = false;
    }
}).onmouseup(function(e){ 
    analyzeSelection();
});
// Rest wie oben:
dojo.connect(dojo.byId("myBodyID"), "onkeypress", function(e){
   switch(e.charOrCode){
    case dojo.keys.copyKey && 'c':
        //jetzt z.B. mittels dojo.style() die Schrift schwarz
        setTimeout(reHyphenate,80);
    break;
   }
});
dojo.connect(window, "onblur", "reHyphenate");
}}}

Original comment by sebila...@googlemail.com on 4 Apr 2010 at 10:04

GoogleCodeExporter commented 9 years ago
You can alter the selection text before it's copied if you listen to the oncopy 
event. Getting it right cross-browser 
is tricky, but this code has been tested on Safari 4, Chrome, FF 3.0-3.6, and 
IE 8.

http://github.com/aristus/sweet-justice/blob/master/sweet-justice.js

Original comment by aris...@gmail.com on 4 May 2010 at 6:02

GoogleCodeExporter commented 9 years ago
Thanks, great job.
Really nice!

Original comment by mathiasn...@gmail.com on 6 May 2010 at 12:01

GoogleCodeExporter commented 9 years ago
It's in the trunk (since rev705)

Original comment by mathiasn...@gmail.com on 6 May 2010 at 12:49

GoogleCodeExporter commented 9 years ago

Original comment by mathiasn...@gmail.com on 3 Jun 2010 at 2:09

GoogleCodeExporter commented 9 years ago
Issue 92 has been merged into this issue.

Original comment by mathiasn...@gmail.com on 13 Jun 2010 at 8:15