🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.java
Article #1

Re: jak pobrać z niego aktualną pozycję kursora z takiego elementu <div contenteditable="true" id="newpostedit" placeholder="pod...

#1
From: Andrzej Nowak
Date: Sat, 24 May 2025 12:00
31 lines
2345 bytes

<div contenteditable="true" id="newpostedit" placeholder="podpowiedż">
</div>

<script>
function getCursorPosition() {
   const selection = window.getSelection();
   if (selection.rangeCount > 0) {
     const range = selection.getRangeAt(0);
     const preCaretRange = range.cloneRange();
  
preCaretRange.selectNodeContents(document.getElementById('newpostedit'));
     preCaretRange.setEnd(range.endContainer, range.endOffset);
     const cursorPosition = preCaretRange.toString().length;
     return cursorPosition;
   }
   return 0; // Zwróć 0 jeśli nie ma zaznaczenia lub zakresu
}

// Przykład użycia:
document.getElementById('newpostedit').addEventListener('keyup', () => {
   const position = getCursorPosition();
   console.log('Pozycja kursora:', position);
});

document.getElementById('newpostedit').addEventListener('click', () => {
   const position = getCursorPosition();
   console.log('Pozycja kursora po kliknięciu:', position);
});
</script>
Technical Details
Message-ID: <100scdm$10ni5$1@news.icm.edu.pl>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!ygg-srl.newsdeef.eu!srl.newsdeef.eu!news.hispagatos.org!news.nntp4.net!weretis.net!feeder8.news.weretis.net!3.eu.feeder.erje.net!feeder.erje.net!newsfeed.pionier.net.pl!news.man.poznan.pl!news.icm.edu.pl!.POSTED.45-11-61-36.ip4.greenlan.pl!not-for-mail
References: <100pied$japk$1@paganini.bofh.team>

Show Full Headers
Complete Article Headers
Message-ID: <100scdm$10ni5$1@news.icm.edu.pl>
Subject: Re: jak pobrać z niego aktualną pozycję kursora z takiego elementu <div contenteditable="true" id="newpostedit" placeholder="podpowiedż">,</div>
Date: Sat, 24 May 2025 14:00:54 +0200
From: Andrzej Nowak <rocky@xxx.xx>
References: <100pied$japk$1@paganini.bofh.team>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!ygg-srl.newsdeef.eu!srl.newsdeef.eu!news.hispagatos.org!news.nntp4.net!weretis.net!feeder8.news.weretis.net!3.eu.feeder.erje.net!feeder.erje.net!newsfeed.pionier.net.pl!news.man.poznan.pl!news.icm.edu.pl!.POSTED.45-11-61-36.ip4.greenlan.pl!not-for-mail
Newsgroups: pl.comp.lang.java
Organization: ICM, Uniwersytet Warszawski
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 24 May 2025 12:00:54 -0000 (UTC)
Injection-Info: news.icm.edu.pl; posting-host="45-11-61-36.ip4.greenlan.pl:45.11.61.36";
 logging-data="1072709"; mail-complaints-to="usenet@news.icm.edu.pl"
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <100pied$japk$1@paganini.bofh.team>